apt::params: Complete $xfacts.
[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        = $::apt::xfacts['lsbdistcodename'],
8   $repos          = 'main',
9   $include_src    = false,
10   $include_deb    = true,
11   $key            = undef,
12   $pin            = false,
13   $architecture   = undef,
14   $trusted_source = false,
15 ) {
16   validate_string($architecture, $comment, $location, $repos)
17   validate_bool($trusted_source, $include_src, $include_deb)
18
19   unless $release {
20     fail('lsbdistcodename fact not available: release parameter required')
21   }
22
23   $_before = Apt::Setting["list-${title}"]
24
25   if $key {
26     if is_hash($key) {
27       unless $key['id'] {
28         fail('key hash must contain at least an id entry')
29       }
30       $_key = merge($::apt::source_key_defaults, $key)
31     } else {
32       validate_string($key)
33       $_key = $key
34     }
35   }
36
37   apt::setting { "list-${name}":
38     ensure  => $ensure,
39     content => template('apt/_header.erb', 'apt/source.list.erb'),
40   }
41
42   if ($pin != false) {
43     # Get the host portion out of the url so we can pin to origin
44     $url_split = split($location, '/')
45     $host      = $url_split[2]
46
47     apt::pin { $name:
48       ensure   => $ensure,
49       priority => $pin,
50       before   => $_before,
51       origin   => $host,
52     }
53   }
54
55   # We do not want to remove keys when the source is absent.
56   if $key and ($ensure == 'present') {
57     if is_hash($_key) {
58       apt::key { "Add key: ${_key['id']} from Apt::Source ${title}":
59         ensure  => present,
60         id      => $_key['id'],
61         server  => $_key['server'],
62         content => $_key['content'],
63         source  => $_key['source'],
64         options => $_key['options'],
65         before  => $_before,
66       }
67     } else {
68       apt::key { "Add key: ${_key} from Apt::Source ${title}":
69         ensure => present,
70         id     => $_key,
71         before => $_before,
72       }
73     }
74   }
75 }