Allow priorities to be zero-padded
[puppet-modules/puppetlabs-apt.git] / manifests / source.pp
1 # source.pp
2 # add an apt source
3 define apt::source(
4   $comment           = $name,
5   $ensure            = present,
6   $location          = '',
7   $release           = $::lsbdistcodename,
8   $repos             = 'main',
9   $include_src       = false,
10   $include_deb       = true,
11   $key               = undef,
12   $key_server        = 'keyserver.ubuntu.com',
13   $key_content       = undef,
14   $key_source        = undef,
15   $pin               = false,
16   $architecture      = undef,
17   $trusted_source    = false,
18 ) {
19   validate_string($architecture, $comment, $location, $release, $repos, $key_server)
20   validate_bool($trusted_source, $include_src, $include_deb)
21
22   if ! $release {
23     fail('lsbdistcodename fact not available: release parameter required')
24   }
25
26   apt::setting { $name:
27     ensure       => $ensure,
28     setting_type => 'list',
29     content      => template('apt/_header.erb', 'apt/source.list.erb'),
30     notify       => Exec['apt_update'],
31   }
32
33   if ($pin != false) {
34     # Get the host portion out of the url so we can pin to origin
35     $url_split = split($location, '/')
36     $host      = $url_split[2]
37
38     apt::pin { $name:
39       ensure   => $ensure,
40       priority => $pin,
41       before   => Apt::Setting[$name],
42       origin   => $host,
43     }
44   }
45
46   # We do not want to remove keys when the source is absent.
47   if $key and ($ensure == 'present') {
48     apt::key { "Add key: ${key} from Apt::Source ${title}":
49       ensure      => present,
50       key         => $key,
51       key_server  => $key_server,
52       key_content => $key_content,
53       key_source  => $key_source,
54       before      => Apt::Setting[$name],
55     }
56   }
57
58   # Need anchor to provide containment for dependencies.
59   anchor { "apt::source::${name}":
60     require => Class['apt::update'],
61   }
62 }