1 # @summary Main class, includes all other classes.
3 # @see https://docs.puppetlabs.com/references/latest/function.html#createresources for the create resource function
6 # Specifies the provider that should be used by apt::update.
9 # Specifies a keyserver to provide the GPG key. Valid options: a string containing a domain name or a full URL (http://, https://, or
13 # Specifies the default options for apt::key resources.
16 # Supplies options to be passed to the `add-apt-repository` command.
19 # Names the package that provides the `apt-add-repository` command.
22 # Specifies some of the default parameters used by apt::backports. Valid options: a hash made up from the following keys:
24 # @option backports [String] :location
25 # See apt::backports for documentation.
27 # @option backports [String] :repos
28 # See apt::backports for documentation.
30 # @option backports [String] :key
31 # See apt::backports for documentation.
34 # Creates new `apt::conf` resources. Valid options: a hash to be passed to the create_resources function linked above.
37 # Configures various update settings. Valid options: a hash made up from the following keys:
39 # @option update [String] :frequency
40 # Specifies how often to run `apt-get update`. If the exec resource `apt_update` is notified,
41 # `apt-get update` runs regardless of this value.
43 # 'always' (at every Puppet run);
44 # daily' (if the value of `apt_update_last_success` is less than current epoch time minus 86400);
45 # 'weekly' (if the value of `apt_update_last_success` is less than current epoch time minus 604800);
46 # 'reluctantly' (only if the exec resource `apt_update` is notified).
47 # Default: 'reluctantly'.
49 # @option update [Integer] :loglevel
50 # Specifies the log level of logs outputted to the console. Default: undef.
52 # @option update [Integer] :timeout
53 # Specifies how long to wait for the update to complete before canceling it. Valid options: an integer, in seconds. Default: undef.
55 # @option update [Integer] :tries
56 # Specifies how many times to retry the update after receiving a DNS or HTTP error. Default: undef.
59 # Specifies whether to purge any existing settings that aren't managed by Puppet. Valid options: a hash made up from the following keys:
61 # @option purge [Boolean] :sources.list
62 # Specifies whether to purge any unmanaged entries from sources.list. Default false.
64 # @option purge [Boolean] :sources.list.d
65 # Specifies whether to purge any unmanaged entries from sources.list.d. Default false.
67 # @option purge [Boolean] :preferences
68 # Specifies whether to purge any unmanaged entries from preferences. Default false.
70 # @option purge [Boolean] :preferences.d.
71 # Specifies whether to purge any unmanaged entries from preferences.d. Default false.
74 # Configures Apt to connect to a proxy server. Valid options: a hash matching the locally defined type apt::proxy.
77 # Creates new `apt::source` resources. Valid options: a hash to be passed to the create_resources function linked above.
80 # Creates new `apt::key` resources. Valid options: a hash to be passed to the create_resources function linked above.
83 # Creates new `apt::ppa` resources. Valid options: a hash to be passed to the create_resources function linked above.
86 # Creates new `apt::pin` resources. Valid options: a hash to be passed to the create_resources function linked above.
89 # Creates new `apt::setting` resources. Valid options: a hash to be passed to the create_resources function linked above.
91 # @param manage_auth_conf
92 # Specifies whether to manage the /etc/apt/auth.conf file. When true, the file will be overwritten with the entries specified in
93 # the auth_conf_entries parameter. When false, the file will be ignored (note that this does not set the file to absent.
95 # @param auth_conf_entries
96 # An optional array of login configuration settings (hashes) that are recorded in the file /etc/apt/auth.conf. This file has a netrc-like
97 # format (similar to what curl uses) and contains the login configuration for APT sources and proxies that require authentication. See
98 # https://manpages.debian.org/testing/apt/apt_auth.conf.5.en.html for details. If specified each hash must contain the keys machine, login and
99 # password and no others. Specifying manage_auth_conf and not specifying this parameter will set /etc/apt/auth.conf to absent.
101 # @param auth_conf_owner
102 # The owner of the file /etc/apt/auth.conf. Default: '_apt' or 'root' on old releases.
105 # Specifies root directory of Apt executable.
107 # @param sources_list
108 # Specifies the path of the sources_list file to use.
110 # @param sources_list_d
111 # Specifies the path of the sources_list.d file to use.
114 # Specifies the path of the conf.d file to use.
117 # Specifies the path of the preferences file to use.
119 # @param preferences_d
120 # Specifies the path of the preferences.d file to use.
122 # @param config_files
123 # A hash made up of the various configuration files used by Apt.
125 # @param sources_list_force
126 # Specifies whether to perform force purge or delete. Default false.
129 Hash $update_defaults = $apt::params::update_defaults,
130 Hash $purge_defaults = $apt::params::purge_defaults,
131 Hash $proxy_defaults = $apt::params::proxy_defaults,
132 Hash $include_defaults = $apt::params::include_defaults,
133 String $provider = $apt::params::provider,
134 String $keyserver = $apt::params::keyserver,
135 Optional[String] $key_options = $apt::params::key_options,
136 Optional[Array[String]] $ppa_options = $apt::params::ppa_options,
137 Optional[String] $ppa_package = $apt::params::ppa_package,
138 Optional[Hash] $backports = $apt::params::backports,
139 Hash $confs = $apt::params::confs,
140 Hash $update = $apt::params::update,
141 Hash $purge = $apt::params::purge,
142 Apt::Proxy $proxy = $apt::params::proxy,
143 Hash $sources = $apt::params::sources,
144 Hash $keys = $apt::params::keys,
145 Hash $ppas = $apt::params::ppas,
146 Hash $pins = $apt::params::pins,
147 Hash $settings = $apt::params::settings,
148 Boolean $manage_auth_conf = $apt::params::manage_auth_conf,
149 Array[Apt::Auth_conf_entry] $auth_conf_entries = $apt::params::auth_conf_entries,
150 String $auth_conf_owner = $apt::params::auth_conf_owner,
151 String $root = $apt::params::root,
152 String $sources_list = $apt::params::sources_list,
153 String $sources_list_d = $apt::params::sources_list_d,
154 String $conf_d = $apt::params::conf_d,
155 String $preferences = $apt::params::preferences,
156 String $preferences_d = $apt::params::preferences_d,
157 String $apt_conf_d = $apt::params::apt_conf_d,
158 Hash $config_files = $apt::params::config_files,
159 Boolean $sources_list_force = $apt::params::sources_list_force,
161 Hash $source_key_defaults = {
162 'server' => $keyserver,
168 ) inherits apt::params {
169 if $facts['os']['family'] != 'Debian' {
170 fail('This module only works on Debian or derivatives like Ubuntu')
173 if $update['frequency'] {
175 Enum['always','daily','weekly','reluctantly'],
176 $update['frequency'],
179 if $update['timeout'] {
180 assert_type(Integer, $update['timeout'])
182 if $update['tries'] {
183 assert_type(Integer, $update['tries'])
186 $_update = merge($::apt::update_defaults, $update)
187 include ::apt::update
189 if $purge['sources.list'] {
190 assert_type(Boolean, $purge['sources.list'])
192 if $purge['sources.list.d'] {
193 assert_type(Boolean, $purge['sources.list.d'])
195 if $purge['preferences'] {
196 assert_type(Boolean, $purge['preferences'])
198 if $purge['preferences.d'] {
199 assert_type(Boolean, $purge['preferences.d'])
201 if $sources_list_force {
202 assert_type(Boolean, $sources_list_force)
204 if $purge['apt.conf.d'] {
205 assert_type(Boolean, $purge['apt.conf.d'])
208 $_purge = merge($::apt::purge_defaults, $purge)
210 if $proxy['perhost'] {
211 $_perhost = $proxy['perhost'].map |$item| {
212 $_item = merge($apt::proxy_defaults, $item)
213 $_scheme = $_item['https'] ? {
216 $_port = $_item['port'] ? {
217 Integer => ":${_item['port']}",
220 $_target = $_item['direct'] ? {
222 default => "${_scheme}://${_item['host']}${_port}/" }
224 'scheme' => $_scheme,
225 'target' => $_target })
231 $_proxy = merge($apt::proxy_defaults, $proxy, { 'perhost' => $_perhost })
233 $confheadertmp = epp('apt/_conf_header.epp')
234 $proxytmp = epp('apt/proxy.epp', { 'proxies' => $_proxy })
235 $updatestamptmp = epp('apt/15update-stamp.epp')
237 if $_proxy['ensure'] == 'absent' or $_proxy['host'] {
238 apt::setting { 'conf-proxy':
239 ensure => $_proxy['ensure'],
241 content => "${confheadertmp}${proxytmp}",
245 if $sources_list_force {
246 $sources_list_ensure = $_purge['sources.list'] ? {
250 $sources_list_content = $_purge['sources.list'] ? {
255 $sources_list_ensure = $_purge['sources.list'] ? {
259 $sources_list_content = $_purge['sources.list'] ? {
260 true => "# Repos managed by puppet.\n",
265 $preferences_ensure = $_purge['preferences'] ? {
270 apt::setting { 'conf-update-stamp':
272 content => "${confheadertmp}${updatestamptmp}",
275 file { 'sources.list':
276 ensure => $sources_list_ensure,
277 path => $::apt::sources_list,
280 content => $sources_list_content,
281 notify => Class['apt::update'],
284 file { 'sources.list.d':
286 path => $::apt::sources_list_d,
289 purge => $_purge['sources.list.d'],
290 recurse => $_purge['sources.list.d'],
291 notify => Class['apt::update'],
294 file { 'preferences':
295 ensure => $preferences_ensure,
296 path => $::apt::preferences,
299 notify => Class['apt::update'],
302 file { 'preferences.d':
304 path => $::apt::preferences_d,
307 purge => $_purge['preferences.d'],
308 recurse => $_purge['preferences.d'],
309 notify => Class['apt::update'],
314 path => $::apt::apt_conf_d,
317 purge => $_purge['apt.conf.d'],
318 recurse => $_purge['apt.conf.d'],
319 notify => Class['apt::update'],
323 create_resources('apt::conf', $confs)
325 # manage sources if present
327 create_resources('apt::source', $sources)
329 # manage keys if present
331 create_resources('apt::key', $keys)
333 # manage ppas if present
335 create_resources('apt::ppa', $ppas)
337 # manage settings if present
339 create_resources('apt::setting', $settings)
342 if $manage_auth_conf {
343 $auth_conf_ensure = $auth_conf_entries ? {
345 default => 'present',
348 $auth_conf_tmp = epp('apt/auth_conf.epp')
350 file { '/etc/apt/auth.conf':
351 ensure => $auth_conf_ensure,
352 owner => $auth_conf_owner,
355 content => Sensitive("${confheadertmp}${auth_conf_tmp}"),
356 notify => Class['apt::update'],
360 # manage pins if present
362 create_resources('apt::pin', $pins)
365 case $facts['os']['name'] {
367 if versioncmp($facts['os']['release']['major'], '9') >= 0 {
368 ensure_packages(['gnupg'])
372 if versioncmp($facts['os']['release']['full'], '17.04') >= 0 {
373 ensure_packages(['gnupg'])