Merge pull request #445 from mhaskel/updates_everywhere
[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   $file_perms    = {},
7   $notify_update = true,
8 ) {
9
10   $_file = merge($::apt::file_defaults, $file_perms)
11
12   if $content and $source {
13     fail('apt::setting cannot have both content and source')
14   }
15
16   if !$content and !$source {
17     fail('apt::setting needs either of content or source')
18   }
19
20   validate_re($ensure,  ['file', 'present', 'absent'])
21   validate_bool($notify_update)
22
23   $title_array = split($title, '-')
24   $setting_type = $title_array[0]
25   $base_name = join(delete_at($title_array, 0), '-')
26
27   validate_re($setting_type, ['\Aconf\z', '\Apref\z', '\Alist\z'], "apt::setting resource name/title must start with either 'conf-', 'pref-' or 'list-'")
28
29   unless is_integer($priority) {
30     # need this to allow zero-padded priority.
31     validate_re($priority, '^\d+$', 'apt::setting priority must be an integer or a zero-padded integer')
32   }
33
34   if $source {
35     validate_string($source)
36   }
37
38   if $content {
39     validate_string($content)
40   }
41
42   if $setting_type == 'list' {
43     $_priority = ''
44   } else {
45     $_priority = $priority
46   }
47
48   $_path = $::apt::config_files[$setting_type]['path']
49   $_ext  = $::apt::config_files[$setting_type]['ext']
50
51   if $notify_update {
52     $_notify = Exec['apt_update']
53   } else {
54     $_notify = undef
55   }
56
57   file { "${_path}/${_priority}${base_name}${_ext}":
58     ensure  => $ensure,
59     owner   => $_file['owner'],
60     group   => $_file['group'],
61     mode    => $_file['mode'],
62     content => $content,
63     source  => $source,
64     notify  => $_notify,
65   }
66
67   if $notify_update {
68     anchor { "apt::setting::${name}":
69       require => Class['apt::update']
70     }
71   }
72 }