78f007fdbc6ff9815c5287fc67dab8c2b1501ec6
[puppet-modules/puppetlabs-apt.git] / manifests / setting.pp
1 define apt::setting (
2   $setting_type,
3   $base_name  = $title,
4   $priority   = 50,
5   $ensure     = file,
6   $source     = undef,
7   $content    = undef,
8   $file_perms = {},
9 ) {
10
11   $_file = merge($::apt::file_defaults, $file_perms)
12
13   if $content and $source {
14     fail('apt::setting cannot have both content and source')
15   }
16
17   if !$content and !$source {
18     fail('apt::setting needs either of content or source')
19   }
20
21   validate_re($setting_type, ['conf', 'pref', 'list'])
22   validate_re($ensure,  ['file', 'present', 'absent'])
23   validate_string($base_name)
24
25   unless is_integer($priority) {
26     # need this to allow zero-padded priority.
27     validate_re($priority, '^\d+$', 'apt::setting priority must be an integer or a zero-padded integer.')
28   }
29
30   if $source {
31     validate_string($source)
32   }
33
34   if $content {
35     validate_string($content)
36   }
37
38   if $setting_type == 'list' {
39     $_priority = ''
40   } else {
41     $_priority = $priority
42   }
43
44   $_path = $::apt::config_files[$setting_type]['path']
45   $_ext  = $::apt::config_files[$setting_type]['ext']
46
47   file { "${_path}/${_priority}${base_name}${_ext}":
48     ensure  => $ensure,
49     owner   => $_file['owner'],
50     group   => $_file['group'],
51     mode    => $_file['mode'],
52     content => $content,
53     source  => $source,
54   }
55 }