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 $preferences_content = $purge_preferences ? {
60 true => "Explanation: Preferences managed by Puppet\n
61 Explanation: We need a bogus package line because of Debian Bug #732746\n
62 Package: bogus-package\n",
65 if $always_apt_update == true {
66 Exec <| title=='apt_update' |> {
71 $root = $apt::params::root
72 $apt_conf_d = $apt::params::apt_conf_d
73 $sources_list_d = $apt::params::sources_list_d
74 $preferences_d = $apt::params::preferences_d
75 $provider = $apt::params::provider
77 file { 'sources.list':
79 path => "${root}/sources.list",
83 content => $sources_list_content,
84 notify => Exec['apt_update'],
87 file { 'sources.list.d':
89 path => $sources_list_d,
92 purge => $purge_sources_list_d,
93 recurse => $purge_sources_list_d,
94 notify => Exec['apt_update'],
97 file { 'apt-preferences':
99 path => "${root}/preferences",
103 content => $preferences_content,
106 file { 'preferences.d':
108 path => $preferences_d,
111 purge => $purge_preferences_d,
112 recurse => $purge_preferences_d,
115 case $fancy_progress {
117 file { '99progressbar':
119 content => 'Dpkg::Progress-Fancy "1";',
120 path => "${apt_conf_d}/99progressbar",
124 file { '99progressbar':
126 path => "${apt_conf_d}/99progressbar",
129 undef: {} # do nothing
130 default: { fail('Valid values for fancy_progress are true or false') }
137 content => "APT::Get::AllowUnauthenticated 1;\n",
138 path => "${apt_conf_d}/99unauth",
144 path => "${apt_conf_d}/99unauth",
147 undef: { } # do nothing
148 default: { fail('Valid values for disable_keys are true or false') }
151 $proxy_set = $proxy_host ? {
157 ensure => $proxy_set,
158 path => "${apt_conf_d}/01proxy",
159 content => "Acquire::http::Proxy \"http://${proxy_host}:${proxy_port}\";\n",
160 notify => Exec['apt_update'],
166 file { 'old-proxy-file':
168 path => "${apt_conf_d}/proxy",
169 notify => Exec['apt_update'],
172 # Need anchor to provide containment for dependencies.
173 anchor { 'apt::update':
174 require => Class['apt::update'],
177 # manage sources if present
178 if $sources != undef {
179 validate_hash($sources)
180 create_resources('apt::source', $sources)