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.
8 # disable_keys - disables the requirement for all packages to be signed
9 # always_apt_update - rather apt should be updated on every run (intended
10 # for development environments where package updates are frequent)
11 # purge_sources_list - Accepts true or false. Defaults to false If set to
12 # true, Puppet will purge all unmanaged entries from sources.list
13 # purge_sources_list_d - Accepts true or false. Defaults to false. If set
14 # to true, Puppet will purge all unmanaged entries from sources.list.d
15 # update_timeout - Overrides the exec timeout in seconds for apt-get update.
16 # If not set defaults to Exec's default (300)
17 # update_tries - Number of times that `apt-get update` will be tried. Use this
18 # to work around transient DNS and HTTP errors. By default, the command
19 # will only be run once.
29 $always_apt_update = false,
30 $disable_keys = undef,
33 $purge_sources_list = false,
34 $purge_sources_list_d = false,
35 $purge_preferences = false,
36 $purge_preferences_d = false,
37 $update_timeout = undef,
38 $update_tries = undef,
40 $fancy_progress = undef
43 if $::osfamily != 'Debian' {
44 fail('This module only works on Debian or derivatives like Ubuntu')
50 validate_bool($purge_sources_list, $purge_sources_list_d,
51 $purge_preferences, $purge_preferences_d)
53 $sources_list_content = $purge_sources_list ? {
55 true => "# Repos managed by puppet.\n",
58 if $always_apt_update == true {
59 Exec <| title=='apt_update' |> {
64 $root = $apt::params::root
65 $apt_conf_d = $apt::params::apt_conf_d
66 $sources_list_d = $apt::params::sources_list_d
67 $preferences_d = $apt::params::preferences_d
68 $provider = $apt::params::provider
70 file { 'sources.list':
72 path => "${root}/sources.list",
76 content => $sources_list_content,
77 notify => Exec['apt_update'],
80 file { 'sources.list.d':
82 path => $sources_list_d,
85 purge => $purge_sources_list_d,
86 recurse => $purge_sources_list_d,
87 notify => Exec['apt_update'],
90 if $purge_preferences {
91 file { 'apt-preferences':
93 path => "${root}/preferences",
97 file { 'preferences.d':
99 path => $preferences_d,
102 purge => $purge_preferences_d,
103 recurse => $purge_preferences_d,
106 case $fancy_progress {
108 file { '99progressbar':
110 content => 'Dpkg::Progress-Fancy "1";',
111 path => "${apt_conf_d}/99progressbar",
115 file { '99progressbar':
117 path => "${apt_conf_d}/99progressbar",
120 undef: {} # do nothing
121 default: { fail('Valid values for fancy_progress are true or false') }
128 content => "APT::Get::AllowUnauthenticated 1;\n",
129 path => "${apt_conf_d}/99unauth",
135 path => "${apt_conf_d}/99unauth",
138 undef: { } # do nothing
139 default: { fail('Valid values for disable_keys are true or false') }
142 $proxy_set = $proxy_host ? {
148 ensure => $proxy_set,
149 path => "${apt_conf_d}/01proxy",
150 content => "Acquire::http::Proxy \"http://${proxy_host}:${proxy_port}\";\n",
151 notify => Exec['apt_update'],
157 file { 'old-proxy-file':
159 path => "${apt_conf_d}/proxy",
160 notify => Exec['apt_update'],
163 # Need anchor to provide containment for dependencies.
164 anchor { 'apt::update':
165 require => Class['apt::update'],
168 # manage sources if present
169 if $sources != undef {
170 validate_hash($sources)
171 create_resources('apt::source', $sources)