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 $preferences_content = $purge_preferences ? {
59 true => "Explanation: Preferences managed by Puppet\n
60 Explanation: We need a bogus package line because of Debian Bug #732746\n
61 Package: bogus-package\n",
64 if $always_apt_update == true {
65 Exec <| title=='apt_update' |> {
70 $root = $apt::params::root
71 $apt_conf_d = $apt::params::apt_conf_d
72 $sources_list_d = $apt::params::sources_list_d
73 $preferences_d = $apt::params::preferences_d
74 $provider = $apt::params::provider
76 file { 'sources.list':
78 path => "${root}/sources.list",
82 content => $sources_list_content,
83 notify => Exec['apt_update'],
86 file { 'sources.list.d':
88 path => $sources_list_d,
91 purge => $purge_sources_list_d,
92 recurse => $purge_sources_list_d,
93 notify => Exec['apt_update'],
96 file { 'apt-preferences':
98 path => "${root}/preferences",
102 content => $preferences_content,
105 file { 'preferences.d':
107 path => $preferences_d,
110 purge => $purge_preferences_d,
111 recurse => $purge_preferences_d,
118 content => "APT::Get::AllowUnauthenticated 1;\n",
119 path => "${apt_conf_d}/99unauth",
125 path => "${apt_conf_d}/99unauth",
128 undef: { } # do nothing
129 default: { fail('Valid values for disable_keys are true or false') }
132 $proxy_set = $proxy_host ? {
137 file { 'configure-apt-proxy':
138 ensure => $proxy_set,
139 path => "${apt_conf_d}/proxy",
140 content => "Acquire::http::Proxy \"http://${proxy_host}:${proxy_port}\";\n",
141 notify => Exec['apt_update'],
147 # Need anchor to provide containment for dependencies.
148 anchor { 'apt::update':
149 require => Class['apt::update'],
152 # manage sources if present
153 if $sources != undef {
154 validate_hash($sources)
155 create_resources('apt::source', $sources)