3 # This module manages the initial configuration of apt.
5 # The parameters listed here are not required in general and were
6 # added for use cases related to development environments.
11 # Disables the requirement for all packages to be signed
13 # [*always_apt_update*]
14 # Rather apt should be updated on every run (intended
15 # for development environments where package updates are frequent)
17 # [*apt_update_frequency*]
18 # String: Supported values:
19 # **always**: Will fire `apt-get update` at every puppet run. Intended to
20 # deprecate the `always_apt_update` parameter.
21 # *daily**: Trigger `apt-get update` if the value of the fact
22 # `apt_update_last_success` is less than current epoch time - 86400.
23 # *notifying the apt_update exec will trigger apt-get update regardless*
24 # *weekly**: Trigger `apt-get update` if the value of the fact
25 # `apt_update_last_success` is less than current epoch time - 604800.
26 # *notifying the apt_update exec will trigger apt-get update regardless*
27 # *reluctantly**: *Default* only run apt-get update if the exec resource `apt_update` is notified.
29 # [*purge_sources_list*]
30 # Accepts true or false. Defaults to false If set to
31 # true, Puppet will purge all unmanaged entries from sources.list
33 # [*purge_sources_list_d*]
34 # Accepts true or false. Defaults to false. If set
35 # to true, Puppet will purge all unmanaged entries from sources.list.d
38 # Overrides the exec timeout in seconds for apt-get update.
39 # If not set defaults to Exec's default (300)
42 # Number of times that `apt-get update` will be tried. Use this
43 # to work around transient DNS and HTTP errors. By default, the command
44 # will only be run once.
52 # puppetlabs/stdlib >= 2.2.1
55 $always_apt_update = false,
56 $apt_update_frequency = 'reluctantly',
57 $disable_keys = undef,
60 $purge_sources_list = false,
61 $purge_sources_list_d = false,
62 $purge_preferences = false,
63 $purge_preferences_d = false,
64 $update_timeout = undef,
65 $update_tries = undef,
67 $fancy_progress = undef
70 if $::osfamily != 'Debian' {
71 fail('This module only works on Debian or derivatives like Ubuntu')
74 $frequency_options = ['always','daily','weekly','reluctantly']
75 validate_re($apt_update_frequency, $frequency_options)
79 validate_bool($purge_sources_list, $purge_sources_list_d,
80 $purge_preferences, $purge_preferences_d)
82 $sources_list_content = $purge_sources_list ? {
84 true => "# Repos managed by puppet.\n",
87 if $always_apt_update == true {
88 Exec <| title=='apt_update' |> {
93 file { '/etc/apt/apt.conf.d/15update-stamp':
95 content => 'APT::Update::Post-Invoke-Success {"touch /var/lib/apt/periodic/update-success-stamp 2>/dev/null || true";};',
101 $root = $apt::params::root
102 $apt_conf_d = $apt::params::apt_conf_d
103 $sources_list_d = $apt::params::sources_list_d
104 $preferences_d = $apt::params::preferences_d
105 $provider = $apt::params::provider
107 file { 'sources.list':
109 path => "${root}/sources.list",
113 content => $sources_list_content,
114 notify => Exec['apt_update'],
117 file { 'sources.list.d':
119 path => $sources_list_d,
122 purge => $purge_sources_list_d,
123 recurse => $purge_sources_list_d,
124 notify => Exec['apt_update'],
127 if $purge_preferences {
128 file { 'apt-preferences':
130 path => "${root}/preferences",
134 file { 'preferences.d':
136 path => $preferences_d,
139 purge => $purge_preferences_d,
140 recurse => $purge_preferences_d,
143 case $fancy_progress {
145 file { '99progressbar':
147 content => 'Dpkg::Progress-Fancy "1";',
148 path => "${apt_conf_d}/99progressbar",
152 file { '99progressbar':
154 path => "${apt_conf_d}/99progressbar",
157 undef: {} # do nothing
158 default: { fail('Valid values for fancy_progress are true or false') }
165 content => "APT::Get::AllowUnauthenticated 1;\n",
166 path => "${apt_conf_d}/99unauth",
172 path => "${apt_conf_d}/99unauth",
175 undef: { } # do nothing
176 default: { fail('Valid values for disable_keys are true or false') }
183 path => "${apt_conf_d}/01proxy",
184 notify => Exec['apt_update'],
190 path => "${apt_conf_d}/01proxy",
191 content => "Acquire::http::Proxy \"http://${proxy_host}:${proxy_port}\";\n",
192 notify => Exec['apt_update'],
200 file { 'old-proxy-file':
202 path => "${apt_conf_d}/proxy",
203 notify => Exec['apt_update'],
206 # Need anchor to provide containment for dependencies.
207 anchor { 'apt::update':
208 require => Class['apt::update'],
211 # manage sources if present
212 if $sources != undef {
213 validate_hash($sources)
214 create_resources('apt::source', $sources)