Mercurial > repos > other > Puppet
comparison modules/apt/manifests/init.pp @ 386:3fce34f642f1
Add a PHP module to handle platform differences
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Mon, 03 Jan 2022 17:09:39 +0000 |
parents | |
children | adf6fe9bbc17 |
comparison
equal
deleted
inserted
replaced
385:d9009f54eb23 | 386:3fce34f642f1 |
---|---|
1 # @summary Main class, includes all other classes. | |
2 # | |
3 # @see https://docs.puppetlabs.com/references/latest/function.html#createresources for the create resource function | |
4 # | |
5 # @param provider | |
6 # Specifies the provider that should be used by apt::update. | |
7 # | |
8 # @param keyserver | |
9 # Specifies a keyserver to provide the GPG key. Valid options: a string containing a domain name or a full URL (http://, https://, or | |
10 # hkp://). | |
11 # | |
12 # @param key_options | |
13 # Specifies the default options for apt::key resources. | |
14 # | |
15 # @param ppa_options | |
16 # Supplies options to be passed to the `add-apt-repository` command. | |
17 # | |
18 # @param ppa_package | |
19 # Names the package that provides the `apt-add-repository` command. | |
20 # | |
21 # @param backports | |
22 # Specifies some of the default parameters used by apt::backports. Valid options: a hash made up from the following keys: | |
23 # | |
24 # @option backports [String] :location | |
25 # See apt::backports for documentation. | |
26 # | |
27 # @option backports [String] :repos | |
28 # See apt::backports for documentation. | |
29 # | |
30 # @option backports [String] :key | |
31 # See apt::backports for documentation. | |
32 # | |
33 # @param confs | |
34 # Creates new `apt::conf` resources. Valid options: a hash to be passed to the create_resources function linked above. | |
35 # | |
36 # @param update | |
37 # Configures various update settings. Valid options: a hash made up from the following keys: | |
38 # | |
39 # @option update [String] :frequency | |
40 # Specifies how often to run `apt-get update`. If the exec resource `apt_update` is notified, `apt-get update` runs regardless of this value. | |
41 # Valid options: 'always' (at every Puppet run); 'daily' (if the value of `apt_update_last_success` is less than current epoch time minus 86400); | |
42 # 'weekly' (if the value of `apt_update_last_success` is less than current epoch time minus 604800); and 'reluctantly' (only if the exec resource | |
43 # `apt_update` is notified). Default: 'reluctantly'. | |
44 # | |
45 # @option update [Integer] :loglevel | |
46 # Specifies the log level of logs outputted to the console. Default: undef. | |
47 # | |
48 # @option update [Integer] :timeout | |
49 # Specifies how long to wait for the update to complete before canceling it. Valid options: an integer, in seconds. Default: undef. | |
50 # | |
51 # @option update [Integer] :tries | |
52 # Specifies how many times to retry the update after receiving a DNS or HTTP error. Default: undef. | |
53 # | |
54 # @param purge | |
55 # Specifies whether to purge any existing settings that aren't managed by Puppet. Valid options: a hash made up from the following keys: | |
56 # | |
57 # @option purge [Boolean] :sources.list | |
58 # Specifies whether to purge any unmanaged entries from sources.list. Default false. | |
59 # | |
60 # @option purge [Boolean] :sources.list.d | |
61 # Specifies whether to purge any unmanaged entries from sources.list.d. Default false. | |
62 # | |
63 # @option purge [Boolean] :preferences | |
64 # Specifies whether to purge any unmanaged entries from preferences. Default false. | |
65 # | |
66 # @option purge [Boolean] :preferences.d. | |
67 # Specifies whether to purge any unmanaged entries from preferences.d. Default false. | |
68 # | |
69 # @param proxy | |
70 # Configures Apt to connect to a proxy server. Valid options: a hash matching the locally defined type apt::proxy. | |
71 # | |
72 # @param sources | |
73 # Creates new `apt::source` resources. Valid options: a hash to be passed to the create_resources function linked above. | |
74 # | |
75 # @param keys | |
76 # Creates new `apt::key` resources. Valid options: a hash to be passed to the create_resources function linked above. | |
77 # | |
78 # @param ppas | |
79 # Creates new `apt::ppa` resources. Valid options: a hash to be passed to the create_resources function linked above. | |
80 # | |
81 # @param pins | |
82 # Creates new `apt::pin` resources. Valid options: a hash to be passed to the create_resources function linked above. | |
83 # | |
84 # @param settings | |
85 # Creates new `apt::setting` resources. Valid options: a hash to be passed to the create_resources function linked above. | |
86 # | |
87 # @param manage_auth_conf | |
88 # Specifies whether to manage the /etc/apt/auth.conf file. When true, the file will be overwritten with the entries specified in | |
89 # the auth_conf_entries parameter. When false, the file will be ignored (note that this does not set the file to absent. | |
90 # | |
91 # @param auth_conf_entries | |
92 # An optional array of login configuration settings (hashes) that are recorded in the file /etc/apt/auth.conf. This file has a netrc-like | |
93 # format (similar to what curl uses) and contains the login configuration for APT sources and proxies that require authentication. See | |
94 # https://manpages.debian.org/testing/apt/apt_auth.conf.5.en.html for details. If specified each hash must contain the keys machine, login and | |
95 # password and no others. Specifying manage_auth_conf and not specifying this parameter will set /etc/apt/auth.conf to absent. | |
96 # | |
97 # @param auth_conf_owner | |
98 # The owner of the file /etc/apt/auth.conf. Default: '_apt' or 'root' on old releases. | |
99 # | |
100 # @param root | |
101 # Specifies root directory of Apt executable. | |
102 # | |
103 # @param sources_list | |
104 # Specifies the path of the sources_list file to use. | |
105 # | |
106 # @param sources_list_d | |
107 # Specifies the path of the sources_list.d file to use. | |
108 # | |
109 # @param conf_d | |
110 # Specifies the path of the conf.d file to use. | |
111 # | |
112 # @param preferences | |
113 # Specifies the path of the preferences file to use. | |
114 # | |
115 # @param preferences_d | |
116 # Specifies the path of the preferences.d file to use. | |
117 # | |
118 # @param config_files | |
119 # A hash made up of the various configuration files used by Apt. | |
120 # | |
121 # @param sources_list_force | |
122 # Specifies whether to perform force purge or delete. Default false. | |
123 # | |
124 class apt ( | |
125 Hash $update_defaults = $apt::params::update_defaults, | |
126 Hash $purge_defaults = $apt::params::purge_defaults, | |
127 Hash $proxy_defaults = $apt::params::proxy_defaults, | |
128 Hash $include_defaults = $apt::params::include_defaults, | |
129 String $provider = $apt::params::provider, | |
130 String $keyserver = $apt::params::keyserver, | |
131 Optional[String] $key_options = $apt::params::key_options, | |
132 Optional[String] $ppa_options = $apt::params::ppa_options, | |
133 Optional[String] $ppa_package = $apt::params::ppa_package, | |
134 Optional[Hash] $backports = $apt::params::backports, | |
135 Hash $confs = $apt::params::confs, | |
136 Hash $update = $apt::params::update, | |
137 Hash $purge = $apt::params::purge, | |
138 Apt::Proxy $proxy = $apt::params::proxy, | |
139 Hash $sources = $apt::params::sources, | |
140 Hash $keys = $apt::params::keys, | |
141 Hash $ppas = $apt::params::ppas, | |
142 Hash $pins = $apt::params::pins, | |
143 Hash $settings = $apt::params::settings, | |
144 Boolean $manage_auth_conf = $apt::params::manage_auth_conf, | |
145 Array[Apt::Auth_conf_entry] | |
146 $auth_conf_entries = $apt::params::auth_conf_entries, | |
147 String $auth_conf_owner = $apt::params::auth_conf_owner, | |
148 String $root = $apt::params::root, | |
149 String $sources_list = $apt::params::sources_list, | |
150 String $sources_list_d = $apt::params::sources_list_d, | |
151 String $conf_d = $apt::params::conf_d, | |
152 String $preferences = $apt::params::preferences, | |
153 String $preferences_d = $apt::params::preferences_d, | |
154 String $apt_conf_d = $apt::params::apt_conf_d, | |
155 Hash $config_files = $apt::params::config_files, | |
156 Boolean $sources_list_force = $apt::params::sources_list_force, | |
157 | |
158 Hash $source_key_defaults = { | |
159 'server' => $keyserver, | |
160 'options' => undef, | |
161 'content' => undef, | |
162 'source' => undef, | |
163 } | |
164 | |
165 ) inherits apt::params { | |
166 | |
167 if $facts['os']['family'] != 'Debian' { | |
168 fail('This module only works on Debian or derivatives like Ubuntu') | |
169 } | |
170 | |
171 if $update['frequency'] { | |
172 assert_type( | |
173 Enum['always','daily','weekly','reluctantly'], | |
174 $update['frequency'], | |
175 ) | |
176 } | |
177 if $update['timeout'] { | |
178 assert_type(Integer, $update['timeout']) | |
179 } | |
180 if $update['tries'] { | |
181 assert_type(Integer, $update['tries']) | |
182 } | |
183 | |
184 $_update = merge($::apt::update_defaults, $update) | |
185 include ::apt::update | |
186 | |
187 if $purge['sources.list'] { | |
188 assert_type(Boolean, $purge['sources.list']) | |
189 } | |
190 if $purge['sources.list.d'] { | |
191 assert_type(Boolean, $purge['sources.list.d']) | |
192 } | |
193 if $purge['preferences'] { | |
194 assert_type(Boolean, $purge['preferences']) | |
195 } | |
196 if $purge['preferences.d'] { | |
197 assert_type(Boolean, $purge['preferences.d']) | |
198 } | |
199 if $sources_list_force { | |
200 assert_type(Boolean, $sources_list_force) | |
201 } | |
202 if $purge['apt.conf.d'] { | |
203 assert_type(Boolean, $purge['apt.conf.d']) | |
204 } | |
205 | |
206 $_purge = merge($::apt::purge_defaults, $purge) | |
207 | |
208 if $proxy['perhost'] { | |
209 $_perhost = $proxy['perhost'].map |$item| { | |
210 $_item = merge($apt::proxy_defaults, $item) | |
211 $_scheme = $_item['https'] ? { | |
212 true => 'https', | |
213 default => 'http' } | |
214 $_port = $_item['port'] ? { | |
215 Integer => ":${_item['port']}", | |
216 default => '' | |
217 } | |
218 $_target = $_item['direct'] ? { | |
219 true => 'DIRECT', | |
220 default => "${_scheme}://${_item['host']}${_port}/" } | |
221 merge($item, { | |
222 'scheme' => $_scheme, | |
223 'target' => $_target }) | |
224 } | |
225 } else { | |
226 $_perhost = {} | |
227 } | |
228 | |
229 $_proxy = merge($apt::proxy_defaults, $proxy, { 'perhost' => $_perhost } ) | |
230 | |
231 $confheadertmp = epp('apt/_conf_header.epp') | |
232 $proxytmp = epp('apt/proxy.epp', {'proxies' => $_proxy}) | |
233 $updatestamptmp = epp('apt/15update-stamp.epp') | |
234 | |
235 if $_proxy['ensure'] == 'absent' or $_proxy['host'] { | |
236 apt::setting { 'conf-proxy': | |
237 ensure => $_proxy['ensure'], | |
238 priority => '01', | |
239 content => "${confheadertmp}${proxytmp}", | |
240 } | |
241 } | |
242 | |
243 if $sources_list_force { | |
244 $sources_list_ensure = $_purge['sources.list'] ? { | |
245 true => absent, | |
246 default => file, | |
247 } | |
248 $sources_list_content = $_purge['sources.list'] ? { | |
249 true => nil, | |
250 default => undef, | |
251 } | |
252 } | |
253 else | |
254 { | |
255 $sources_list_ensure = $_purge['sources.list'] ? { | |
256 true => file, | |
257 default => file, | |
258 } | |
259 $sources_list_content = $_purge['sources.list'] ? { | |
260 true => "# Repos managed by puppet.\n", | |
261 default => undef, | |
262 } | |
263 } | |
264 | |
265 $preferences_ensure = $_purge['preferences'] ? { | |
266 true => absent, | |
267 default => file, | |
268 } | |
269 | |
270 if $_update['frequency'] == 'always' { | |
271 Exec <| title=='apt_update' |> { | |
272 refreshonly => false, | |
273 } | |
274 } | |
275 | |
276 apt::setting { 'conf-update-stamp': | |
277 priority => 15, | |
278 content => "${confheadertmp}${updatestamptmp}", | |
279 } | |
280 | |
281 file { 'sources.list': | |
282 ensure => $sources_list_ensure, | |
283 path => $::apt::sources_list, | |
284 owner => root, | |
285 group => root, | |
286 content => $sources_list_content, | |
287 notify => Class['apt::update'], | |
288 } | |
289 | |
290 file { 'sources.list.d': | |
291 ensure => directory, | |
292 path => $::apt::sources_list_d, | |
293 owner => root, | |
294 group => root, | |
295 purge => $_purge['sources.list.d'], | |
296 recurse => $_purge['sources.list.d'], | |
297 notify => Class['apt::update'], | |
298 } | |
299 | |
300 file { 'preferences': | |
301 ensure => $preferences_ensure, | |
302 path => $::apt::preferences, | |
303 owner => root, | |
304 group => root, | |
305 notify => Class['apt::update'], | |
306 } | |
307 | |
308 file { 'preferences.d': | |
309 ensure => directory, | |
310 path => $::apt::preferences_d, | |
311 owner => root, | |
312 group => root, | |
313 purge => $_purge['preferences.d'], | |
314 recurse => $_purge['preferences.d'], | |
315 notify => Class['apt::update'], | |
316 } | |
317 | |
318 file { 'apt.conf.d': | |
319 ensure => directory, | |
320 path => $::apt::apt_conf_d, | |
321 owner => root, | |
322 group => root, | |
323 purge => $_purge['apt.conf.d'], | |
324 recurse => $_purge['apt.conf.d'], | |
325 notify => Class['apt::update'], | |
326 } | |
327 | |
328 if $confs { | |
329 create_resources('apt::conf', $confs) | |
330 } | |
331 # manage sources if present | |
332 if $sources { | |
333 create_resources('apt::source', $sources) | |
334 } | |
335 # manage keys if present | |
336 if $keys { | |
337 create_resources('apt::key', $keys) | |
338 } | |
339 # manage ppas if present | |
340 if $ppas { | |
341 create_resources('apt::ppa', $ppas) | |
342 } | |
343 # manage settings if present | |
344 if $settings { | |
345 create_resources('apt::setting', $settings) | |
346 } | |
347 | |
348 if $manage_auth_conf { | |
349 $auth_conf_ensure = $auth_conf_entries ? { | |
350 [] => 'absent', | |
351 default => 'present', | |
352 } | |
353 | |
354 $auth_conf_tmp = epp('apt/auth_conf.epp') | |
355 | |
356 file { '/etc/apt/auth.conf': | |
357 ensure => $auth_conf_ensure, | |
358 owner => $auth_conf_owner, | |
359 group => 'root', | |
360 mode => '0600', | |
361 content => Sensitive("${confheadertmp}${auth_conf_tmp}"), | |
362 notify => Class['apt::update'], | |
363 } | |
364 } | |
365 | |
366 # manage pins if present | |
367 if $pins { | |
368 create_resources('apt::pin', $pins) | |
369 } | |
370 | |
371 # required for adding GPG keys on Debian 9 (and derivatives) | |
372 ensure_packages(['gnupg']) | |
373 } |