(MODULES-1156, MODULES-769) Remove unnecessary anchors
[puppet-modules/puppetlabs-apt.git] / manifests / setting.pp
1 define apt::setting (
2   $priority      = 50,
3   $ensure        = file,
4   $source        = undef,
5   $content       = undef,
6   $notify_update = true,
7 ) {
8
9   if $content and $source {
10     fail('apt::setting cannot have both content and source')
11   }
12
13   if !$content and !$source {
14     fail('apt::setting needs either of content or source')
15   }
16
17   validate_re($ensure,  ['file', 'present', 'absent'])
18   validate_bool($notify_update)
19
20   $title_array = split($title, '-')
21   $setting_type = $title_array[0]
22   $base_name = join(delete_at($title_array, 0), '-')
23
24   validate_re($setting_type, ['\Aconf\z', '\Apref\z', '\Alist\z'], "apt::setting resource name/title must start with either 'conf-', 'pref-' or 'list-'")
25
26   unless is_integer($priority) {
27     # need this to allow zero-padded priority.
28     validate_re($priority, '^\d+$', 'apt::setting priority must be an integer or a zero-padded integer')
29   }
30
31   if $source {
32     validate_string($source)
33   }
34
35   if $content {
36     validate_string($content)
37   }
38
39   if $setting_type == 'list' {
40     $_priority = ''
41   } else {
42     $_priority = $priority
43   }
44
45   $_path = $::apt::config_files[$setting_type]['path']
46   $_ext  = $::apt::config_files[$setting_type]['ext']
47
48   if $notify_update {
49     $_notify = Exec['apt_update']
50   } else {
51     $_notify = undef
52   }
53
54   file { "${_path}/${_priority}${base_name}${_ext}":
55     ensure  => $ensure,
56     owner   => 'root',
57     group   => 'root',
58     mode    => '0644',
59     content => $content,
60     source  => $source,
61     notify  => $_notify,
62   }
63 }