3 # This module manages the initial configuration of apt.
6 # The parameters listed here are not required in general and were
7 # added for use cases related to development environments.
9 # disable_keys - disables the requirement for all packages to be signed
11 # always_apt_update - rather apt should be updated on every run (intended
12 # for development environments where package updates are frequent)
14 # apt_update_frequency - *string* Supported values:
15 # **always**: Will fire `apt-get update` at every puppet run. Intended to
16 # deprecate the `always_apt_update` parameter.
17 # **daily**: Trigger `apt-get update` if the value of the fact
18 # `apt_update_last_success` is less than current epoch time - 86400.
19 # *notifying the apt_update exec will trigger apt-get update regardless*
20 # **weekly**: Trigger `apt-get update` if the value of the fact
21 # `apt_update_last_success` is less than current epoch time - 604800.
22 # *notifying the apt_update exec will trigger apt-get update regardless*
23 # **reluctantly**: *Default* only run apt-get update if the exec resource `apt_update` is notified.
25 # purge_sources_list - Accepts true or false. Defaults to false If set to
26 # true, Puppet will purge all unmanaged entries from sources.list
28 # purge_sources_list_d - Accepts true or false. Defaults to false. If set
29 # to true, Puppet will purge all unmanaged entries from sources.list.d
31 # update_timeout - Overrides the exec timeout in seconds for apt-get update.
32 # If not set defaults to Exec's default (300)
34 # update_tries - Number of times that `apt-get update` will be tried. Use this
35 # to work around transient DNS and HTTP errors. By default, the command
36 # will only be run once.
46 $always_apt_update = false,
47 $apt_update_frequency = 'reluctantly',
48 $disable_keys = undef,
51 $purge_sources_list = false,
52 $purge_sources_list_d = false,
53 $purge_preferences = false,
54 $purge_preferences_d = false,
55 $update_timeout = undef,
56 $update_tries = undef,
58 $fancy_progress = undef
61 if $::osfamily != 'Debian' {
62 fail('This module only works on Debian or derivatives like Ubuntu')
65 $frequency_options = ['always','daily','weekly','reluctantly']
66 validate_re($apt_update_frequency, $frequency_options)
70 validate_bool($purge_sources_list, $purge_sources_list_d,
71 $purge_preferences, $purge_preferences_d)
73 $sources_list_content = $purge_sources_list ? {
75 true => "# Repos managed by puppet.\n",
78 if $always_apt_update == true {
79 Exec <| title=='apt_update' |> {
84 file { '/etc/apt/apt.conf.d/15update-stamp':
86 content => 'APT::Update::Post-Invoke-Success {"touch /var/lib/apt/periodic/update-success-stamp 2>/dev/null || true";};',
92 $root = $apt::params::root
93 $apt_conf_d = $apt::params::apt_conf_d
94 $sources_list_d = $apt::params::sources_list_d
95 $preferences_d = $apt::params::preferences_d
96 $provider = $apt::params::provider
98 file { 'sources.list':
100 path => "${root}/sources.list",
104 content => $sources_list_content,
105 notify => Exec['apt_update'],
108 file { 'sources.list.d':
110 path => $sources_list_d,
113 purge => $purge_sources_list_d,
114 recurse => $purge_sources_list_d,
115 notify => Exec['apt_update'],
118 if $purge_preferences {
119 file { 'apt-preferences':
121 path => "${root}/preferences",
125 file { 'preferences.d':
127 path => $preferences_d,
130 purge => $purge_preferences_d,
131 recurse => $purge_preferences_d,
134 case $fancy_progress {
136 file { '99progressbar':
138 content => 'Dpkg::Progress-Fancy "1";',
139 path => "${apt_conf_d}/99progressbar",
143 file { '99progressbar':
145 path => "${apt_conf_d}/99progressbar",
148 undef: {} # do nothing
149 default: { fail('Valid values for fancy_progress are true or false') }
156 content => "APT::Get::AllowUnauthenticated 1;\n",
157 path => "${apt_conf_d}/99unauth",
163 path => "${apt_conf_d}/99unauth",
166 undef: { } # do nothing
167 default: { fail('Valid values for disable_keys are true or false') }
174 path => "${apt_conf_d}/01proxy",
175 notify => Exec['apt_update'],
181 path => "${apt_conf_d}/01proxy",
182 content => "Acquire::http::Proxy \"http://${proxy_host}:${proxy_port}\";\n",
183 notify => Exec['apt_update'],
191 file { 'old-proxy-file':
193 path => "${apt_conf_d}/proxy",
194 notify => Exec['apt_update'],
197 # Need anchor to provide containment for dependencies.
198 anchor { 'apt::update':
199 require => Class['apt::update'],
202 # manage sources if present
203 if $sources != undef {
204 validate_hash($sources)
205 create_resources('apt::source', $sources)