8d876faee026fe43eb73d2b22d70b93f128b1d58
[puppet-modules/puppetlabs-apt.git] / manifests / setting.pp
1 define apt::setting (
2   $setting_type,
3   $priority   = 50,
4   $ensure     = file,
5   $source     = undef,
6   $content    = undef,
7   $file_perms = {},
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($setting_type, ['conf', 'pref', 'list'])
21   validate_re($ensure,  ['file', 'present', 'absent'])
22
23   unless is_integer($priority) {
24     fail('apt::setting priority must be an integer')
25   }
26
27   if $source {
28     validate_string($source)
29   }
30
31   if $content {
32     validate_string($content)
33   }
34
35   if $setting_type == 'list' {
36     $_priority = ''
37   } else {
38     $_priority = $priority
39   }
40
41   $_path = $::apt::config_files[$setting_type]['path']
42   $_ext  = $::apt::config_files[$setting_type]['ext']
43
44   file { "${_path}/${_priority}${title}${_ext}":
45     ensure  => $ensure,
46     owner   => $_file['owner'],
47     group   => $_file['group'],
48     mode    => $_file['mode'],
49     content => $content,
50     source  => $source,
51   }
52 }