1 # @summary Manages the Apt sources in /etc/apt/sources.list.d/.
3 # @example Install the puppetlabs apt source
4 # apt::source { 'puppetlabs':
5 # location => 'http://apt.puppetlabs.com',
8 # id => '6F6B15509CF8E59E6E469F327F438280EF8D349F',
9 # server => 'keyserver.ubuntu.com',
14 # Required, unless ensure is set to 'absent'. Specifies an Apt repository. Valid options: a string containing a repository URL.
17 # Supplies a comment for adding to the Apt source file.
20 # Specifies whether the Apt source file should exist. Valid options: 'present' and 'absent'.
23 # Specifies a distribution of the Apt repository.
26 # Specifies a component of the Apt repository.
29 # Configures include options. Valid options: a hash of available keys.
31 # @option include [Boolean] :deb
32 # Specifies whether to request the distribution's compiled binaries. Default true.
34 # @option include [Boolean] :src
35 # Specifies whether to request the distribution's uncompiled source code. Default false.
38 # Creates a declaration of the apt::key defined type. Valid options: a string to be passed to the `id` parameter of the `apt::key`
39 # defined type, or a hash of `parameter => value` pairs to be passed to `apt::key`'s `id`, `server`, `content`, `source`, `weak_ssl`,
40 # and/or `options` parameters.
43 # Absolute path to a file containing the PGP keyring used to sign this repository. Value is used to set signed-by on the source entry.
44 # See https://wiki.debian.org/DebianRepository/UseThirdParty for details.
47 # Creates a declaration of the apt::pin defined type. Valid options: a number or string to be passed to the `id` parameter of the
48 # `apt::pin` defined type, or a hash of `parameter => value` pairs to be passed to `apt::pin`'s corresponding parameters.
51 # Tells Apt to only download information for specified architectures. Valid options: a string containing one or more architecture names,
52 # separated by commas (e.g., 'i386' or 'i386,alpha,powerpc'). Default: undef (if unspecified, Apt downloads information for all architectures
53 # defined in the Apt::Architectures option).
55 # @param allow_unsigned
56 # Specifies whether to authenticate packages from this release, even if the Release file is not signed or the signature can't be checked.
58 # @param notify_update
59 # Specifies whether to trigger an `apt-get update` run.
62 Optional[String] $location = undef,
63 String $comment = $name,
64 String $ensure = present,
65 Optional[String] $release = undef,
66 String $repos = 'main',
67 Variant[Hash] $include = {},
68 Optional[Variant[String, Hash]] $key = undef,
69 Optional[Stdlib::AbsolutePath] $keyring = undef,
70 Optional[Variant[Hash, Numeric, String]] $pin = undef,
71 Optional[String] $architecture = undef,
72 Boolean $allow_unsigned = false,
73 Boolean $allow_insecure = false,
74 Boolean $notify_update = true,
78 $_before = Apt::Setting["list-${title}"]
81 if fact('os.distro.codename') {
82 $_release = fact('os.distro.codename')
84 fail('os.distro.codename fact not available: release parameter required')
90 if $ensure == 'present' {
92 fail('cannot create a source entry without specifying a location')
94 elsif ($::apt::proxy['https_acng']) and ($location =~ /(?i:^https:\/\/)/) {
95 $_location = regsubst($location, 'https://','http://HTTPS///')
98 $_location = $location
100 # Newer oses, do not need the package for HTTPS transport.
101 $_transport_https_releases = ['9']
102 if (fact('os.release.major') in $_transport_https_releases) and $_location =~ /(?i:^https:\/\/)/ {
103 ensure_packages('apt-transport-https')
104 Package['apt-transport-https'] -> Class['apt::update']
110 $includes = merge($::apt::include_defaults, $include)
112 if $key and $keyring {
113 fail('parameters key and keyring are mutualy exclusive')
119 fail('key hash must contain at least an id entry')
121 $_key = merge($::apt::source_key_defaults, $key)
123 $_key = { 'id' => assert_type(String[1], $key) }
127 $header = epp('apt/_header.epp')
130 $_architecture = regsubst($architecture, '\baarch64\b', 'arm64')
132 $_architecture = undef
135 $sourcelist = epp('apt/source.list.epp', {
136 'comment' => $comment,
137 'includes' => $includes,
138 'options' => delete_undef_values( {
139 'arch' => $architecture,
140 'trusted' => $allow_unsigned ? { true => 'yes', false => undef },
141 'allow-insecure' => $allow_insecure ? { true => 'yes', false => undef },
142 'signed-by' => $keyring,
145 'location' => $_location,
146 'release' => $_release,
150 apt::setting { "list-${name}":
152 content => "${header}${sourcelist}",
153 notify_update => $notify_update,
158 $_pin = merge($pin, { 'ensure' => $ensure, 'before' => $_before })
159 } elsif ($pin =~ Numeric or $pin =~ String) {
160 $url_split = split($location, '[:\/]+')
161 $host = $url_split[1]
165 'before' => $_before,
169 fail('Received invalid value for pin parameter')
171 create_resources('apt::pin', { "${name}" => $_pin })
174 # We do not want to remove keys when the source is absent.
175 if $key and ($ensure == 'present') {
177 if $_key['ensure'] != undef {
178 $_ensure = $_key['ensure']
183 apt::key { "Add key: ${$_key['id']} from Apt::Source ${title}":
186 server => $_key['server'],
187 content => $_key['content'],
188 source => $_key['source'],
189 options => $_key['options'],
190 weak_ssl => $_key['weak_ssl'],