Remove update bundler
[puppet-modules/puppetlabs-apt.git] / manifests / source.pp
1 # source.pp
2 # add an apt source
3 define apt::source(
4   Optional[String] $location                    = undef,
5   String $comment                               = $name,
6   String $ensure                                = present,
7   Optional[String] $release                     = undef,
8   String $repos                                 = 'main',
9   Optional[Variant[Hash]] $include              = {},
10   Optional[Variant[String, Hash]] $key          = undef,
11   Optional[Variant[Hash, Numeric, String]] $pin = undef,
12   Optional[String] $architecture                = undef,
13   Boolean $allow_unsigned                       = false,
14   Boolean $notify_update                        = true,
15 ) {
16
17   # This is needed for compat with 1.8.x
18   include ::apt
19
20   $_before = Apt::Setting["list-${title}"]
21
22   if !$release {
23     if $facts['lsbdistcodename'] {
24       $_release = $facts['lsbdistcodename']
25     } else {
26       fail('lsbdistcodename fact not available: release parameter required')
27     }
28   } else {
29     $_release = $release
30   }
31
32   # Some releases do not support https transport with default installation
33   $_transport_https_releases = [ 'wheezy', 'jessie', 'stretch', 'trusty', 'xenial' ]
34
35   if $ensure == 'present' {
36     if ! $location {
37       fail('cannot create a source entry without specifying a location')
38     } elsif $_release in $_transport_https_releases {
39       $method = split($location, '[:\/]+')[0]
40       if $method == 'https' {
41         ensure_packages('apt-transport-https')
42       }
43     }
44   }
45
46   $includes = merge($::apt::include_defaults, $include)
47
48   if $key {
49     if $key =~ Hash {
50       unless $key['id'] {
51         fail('key hash must contain at least an id entry')
52       }
53       $_key = merge($::apt::source_key_defaults, $key)
54     } else {
55       $_key = { 'id' => assert_type(String[1], $key) }
56     }
57   }
58
59   $header = epp('apt/_header.epp')
60
61   $sourcelist = epp('apt/source.list.epp', {
62     'comment'          => $comment,
63     'includes'         => $includes,
64     'opt_architecture' => $architecture,
65     'allow_unsigned'   => $allow_unsigned,
66     'location'         => $location,
67     'release'          => $_release,
68     'repos'            => $repos,
69   })
70
71   apt::setting { "list-${name}":
72     ensure        => $ensure,
73     content       => "${header}${sourcelist}",
74     notify_update => $notify_update,
75   }
76
77   if $pin {
78     if $pin =~ Hash {
79       $_pin = merge($pin, { 'ensure' => $ensure, 'before' => $_before })
80     } elsif ($pin =~ Numeric or $pin =~ String) {
81       $url_split = split($location, '[:\/]+')
82       $host      = $url_split[1]
83       $_pin = {
84         'ensure'   => $ensure,
85         'priority' => $pin,
86         'before'   => $_before,
87         'origin'   => $host,
88       }
89     } else {
90       fail('Received invalid value for pin parameter')
91     }
92     create_resources('apt::pin', { "${name}" => $_pin })
93   }
94
95   # We do not want to remove keys when the source is absent.
96   if $key and ($ensure == 'present') {
97     if $_key =~ Hash {
98       apt::key { "Add key: ${$_key['id']} from Apt::Source ${title}":
99         ensure  => present,
100         id      => $_key['id'],
101         server  => $_key['server'],
102         content => $_key['content'],
103         source  => $_key['source'],
104         options => $_key['options'],
105         before  => $_before,
106       }
107     }
108   }
109 }