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,
42 if $::osfamily != 'Debian' {
43 fail('This module only works on Debian or derivatives like Ubuntu')
49 validate_bool($purge_sources_list, $purge_sources_list_d,
50 $purge_preferences, $purge_preferences_d)
52 $sources_list_content = $purge_sources_list ? {
54 true => "# Repos managed by puppet.\n",
57 if $lsbdistcodename == 'wheezy' {
58 $preferences_content = undef
61 $preferences_content = $purge_preferences ? {
63 true => "Explanation: Preferences managed by Puppet\n
64 Explanation: We need a bogus package line because of Debian Bug #732746\n
65 Package: bogus-package\n",
69 if $always_apt_update == true {
70 Exec <| title=='apt_update' |> {
75 $root = $apt::params::root
76 $apt_conf_d = $apt::params::apt_conf_d
77 $sources_list_d = $apt::params::sources_list_d
78 $preferences_d = $apt::params::preferences_d
79 $provider = $apt::params::provider
81 file { 'sources.list':
83 path => "${root}/sources.list",
87 content => $sources_list_content,
88 notify => Exec['apt_update'],
91 file { 'sources.list.d':
93 path => $sources_list_d,
96 purge => $purge_sources_list_d,
97 recurse => $purge_sources_list_d,
98 notify => Exec['apt_update'],
101 file { 'apt-preferences':
103 path => "${root}/preferences",
107 content => $preferences_content,
110 file { 'preferences.d':
112 path => $preferences_d,
115 purge => $purge_preferences_d,
116 recurse => $purge_preferences_d,
123 content => "APT::Get::AllowUnauthenticated 1;\n",
124 path => "${apt_conf_d}/99unauth",
130 path => "${apt_conf_d}/99unauth",
133 undef: { } # do nothing
134 default: { fail('Valid values for disable_keys are true or false') }
137 $proxy_set = $proxy_host ? {
143 ensure => $proxy_set,
144 path => "${apt_conf_d}/01proxy",
145 content => "Acquire::http::Proxy \"http://${proxy_host}:${proxy_port}\";\n",
146 notify => Exec['apt_update'],
152 file { 'old-proxy-file':
154 path => "${apt_conf_d}/proxy",
155 notify => Exec['apt_update'],
158 # Need anchor to provide containment for dependencies.
159 anchor { 'apt::update':
160 require => Class['apt::update'],
163 # manage sources if present
164 if $sources != undef {
165 validate_hash($sources)
166 create_resources('apt::source', $sources)