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