|
1 | 1 | # @summary |
2 | 2 | # Framework for patch management as code. Works alongside the puppetlabs/pe_patch or albatrossflavour/os_patching modules |
3 | | -# |
| 3 | +# |
4 | 4 | # @example Using the module with defaults, or controlling options through Hiera |
5 | 5 | # include patching_as_code |
6 | | -# |
| 6 | +# |
7 | 7 | # @example Forcing the classification of pe_patch on PE 2019.8.0+ |
8 | 8 | # class {'patching_as_code': |
9 | 9 | # classify_pe_patch => true |
10 | 10 | # } |
11 | | -# |
| 11 | +# |
12 | 12 | # @example Forcing the use of albatrossflavour/os_patching on PE 2019.8.0+ |
13 | 13 | # class {'patching_as_code': |
14 | 14 | # use_pe_patch => false |
15 | 15 | # } |
16 | | -# |
| 16 | +# |
17 | 17 | # @param Variant[String,Array[String]] patch_group |
18 | 18 | # Name(s) of the patch_group(s) for this node. Must match one or more of the patch groups in $patch_schedule |
19 | 19 | # To assign multiple patch groups, provide this parameter as an array |
|
107 | 107 | # When disabled (default), patches are not installed over a metered link. |
108 | 108 | # @param [Optional[String]] plan_patch_fact |
109 | 109 | # Reserved parameter for running `patching_as_code` via a Plan (future functionality). |
110 | | -# |
| 110 | +# |
111 | 111 | class patching_as_code ( |
112 | 112 | Variant[String,Array[String]] $patch_group, #lint:ignore:parameter_documentation |
113 | 113 | Hash $patch_schedule, |
|
231 | 231 | file { 'patching_configuration.json': |
232 | 232 | ensure => file, |
233 | 233 | path => "${facts['puppet_vardir']}/../../facter/facts.d/patching_configuration.json", |
234 | | - content => to_json_pretty( { # lint:ignore:manifest_whitespace_opening_brace_before |
235 | | - patching_as_code_config => { |
236 | | - allowlist => $allowlist, |
237 | | - blocklist => $blocklist, |
238 | | - high_priority_list => $high_priority_list, |
239 | | - allowlist_choco => $allowlist_choco, |
240 | | - blocklist_choco => $blocklist_choco, |
241 | | - high_priority_list_choco => $high_priority_list_choco, |
242 | | - enable_patching => $enable_patching, |
243 | | - patch_fact => $patch_fact, |
244 | | - patch_group => $patch_groups, |
245 | | - patch_schedule => if $active_pg in ['always', 'never'] { |
246 | | - { $active_pg => 'N/A' } |
247 | | - } else { |
248 | | - $patch_schedule.filter |$item| { $item[0] in $patch_groups } |
| 234 | + content => to_json_pretty( |
| 235 | + { |
| 236 | + patching_as_code_config => { |
| 237 | + allowlist => $allowlist, |
| 238 | + blocklist => $blocklist, |
| 239 | + high_priority_list => $high_priority_list, |
| 240 | + allowlist_choco => $allowlist_choco, |
| 241 | + blocklist_choco => $blocklist_choco, |
| 242 | + high_priority_list_choco => $high_priority_list_choco, |
| 243 | + enable_patching => $enable_patching, |
| 244 | + patch_fact => $patch_fact, |
| 245 | + patch_group => $patch_groups, |
| 246 | + patch_schedule => if $active_pg in ['always', 'never'] { |
| 247 | + { $active_pg => 'N/A' } |
| 248 | + } else { |
| 249 | + $patch_schedule.filter |$item| { $item[0] in $patch_groups } |
| 250 | + }, |
| 251 | + high_priority_patch_group => $high_priority_patch_group, |
| 252 | + post_patch_commands => $post_patch_commands, |
| 253 | + pre_patch_commands => $pre_patch_commands, |
| 254 | + pre_reboot_commands => $pre_reboot_commands, |
| 255 | + patch_on_metered_links => $patch_on_metered_links, |
| 256 | + security_only => $security_only, |
| 257 | + patch_choco => $patch_choco, |
| 258 | + unsafe_process_list => $unsafe_process_list, |
249 | 259 | }, |
250 | | - high_priority_patch_group => $high_priority_patch_group, |
251 | | - post_patch_commands => $post_patch_commands, |
252 | | - pre_patch_commands => $pre_patch_commands, |
253 | | - pre_reboot_commands => $pre_reboot_commands, |
254 | | - patch_on_metered_links => $patch_on_metered_links, |
255 | | - security_only => $security_only, |
256 | | - patch_choco => $patch_choco, |
257 | | - unsafe_process_list => $unsafe_process_list, |
258 | 260 | }, |
259 | | - }, false), |
| 261 | + false, |
| 262 | + ), |
260 | 263 | show_diff => false, |
261 | 264 | } |
262 | 265 |
|
|
434 | 437 | # Run pre-patch commands if provided |
435 | 438 | if ($updates_to_install.count + $choco_updates_to_install.count > 0) { |
436 | 439 | $pre_patch_commands.each | $cmd, $cmd_opts | { |
437 | | - exec { "Patching as Code - Before patching - ${cmd}": |
| 440 | + exec { "Patching as Code - Before patching - ${cmd}": # lint:ignore:exec_idempotency |
438 | 441 | * => delete($cmd_opts, ['before', 'schedule', 'tag']), |
439 | 442 | before => Class["patching_as_code::${0}::patchday"], |
440 | 443 | schedule => 'Patching as Code - Patch Window', |
|
444 | 447 | } |
445 | 448 | if ($high_prio_updates_to_install.count + $high_prio_choco_updates_to_install.count > 0) { |
446 | 449 | $pre_patch_commands.each | $cmd, $cmd_opts | { |
447 | | - exec { "Patching as Code - Before patching (High Priority) - ${cmd}": |
| 450 | + exec { "Patching as Code - Before patching (High Priority) - ${cmd}": # lint:ignore:exec_idempotency |
448 | 451 | * => delete($cmd_opts, ['before', 'schedule', 'tag']), |
449 | 452 | before => Class["patching_as_code::${0}::patchday"], |
450 | 453 | schedule => 'Patching as Code - High Priority Patch Window', |
|
475 | 478 | ensure => file, |
476 | 479 | path => "${facts['puppet_vardir']}/../../patching_as_code/last_run", |
477 | 480 | show_diff => false, |
478 | | - content => Deferred('patching_as_code::last_run', [ |
479 | | - $updates_to_install.unique, |
480 | | - $choco_updates_to_install.unique, |
481 | | - ]), |
| 481 | + content => Deferred('patching_as_code::last_run', |
| 482 | + [ |
| 483 | + $updates_to_install.unique, |
| 484 | + $choco_updates_to_install.unique, |
| 485 | + ], |
| 486 | + ), |
482 | 487 | schedule => 'Patching as Code - Patch Window', |
483 | 488 | require => File["${facts['puppet_vardir']}/../../patching_as_code"], |
484 | 489 | before => Anchor['patching_as_code::post'], |
|
494 | 499 | ensure => file, |
495 | 500 | path => "${facts['puppet_vardir']}/../../patching_as_code/high_prio_last_run", |
496 | 501 | show_diff => false, |
497 | | - content => Deferred('patching_as_code::high_prio_last_run', [ |
498 | | - $high_prio_updates_to_install.unique, |
499 | | - $high_prio_choco_updates_to_install.unique, |
500 | | - ]), |
| 502 | + content => Deferred('patching_as_code::high_prio_last_run', |
| 503 | + [ |
| 504 | + $high_prio_updates_to_install.unique, |
| 505 | + $high_prio_choco_updates_to_install.unique, |
| 506 | + ], |
| 507 | + ), |
501 | 508 | schedule => 'Patching as Code - High Priority Patch Window', |
502 | 509 | require => File["${facts['puppet_vardir']}/../../patching_as_code"], |
503 | 510 | before => Anchor['patching_as_code::post'], |
|
528 | 535 | # Perform post-patching Execs |
529 | 536 | if ($updates_to_install.count + $choco_updates_to_install.count > 0) and $reboot { |
530 | 537 | $post_patch_commands.each | $cmd, $cmd_opts | { |
531 | | - exec { "Patching as Code - After patching - ${cmd}": |
| 538 | + exec { "Patching as Code - After patching - ${cmd}": # lint:ignore:exec_idempotency |
532 | 539 | * => delete($cmd_opts, ['require', 'before', 'schedule', 'tag']), |
533 | 540 | require => Anchor['patching_as_code::post'], |
534 | 541 | schedule => 'Patching as Code - Patch Window', |
|
538 | 545 | } |
539 | 546 | if ($high_prio_updates_to_install.count + $high_prio_choco_updates_to_install.count > 0) and $high_prio_reboot { |
540 | 547 | $post_patch_commands.each | $cmd, $cmd_opts | { |
541 | | - exec { "Patching as Code - After patching (High Priority) - ${cmd}": |
| 548 | + exec { "Patching as Code - After patching (High Priority) - ${cmd}": # lint:ignore:exec_idempotency |
542 | 549 | * => delete($cmd_opts, ['require', 'before', 'schedule', 'tag']), |
543 | 550 | require => Anchor['patching_as_code::post'], |
544 | 551 | schedule => 'Patching as Code - High Priority Patch Window', |
|
610 | 617 | # Do not reboot after patching, just run post_patch commands if given |
611 | 618 | if ($updates_to_install.count + $choco_updates_to_install.count > 0) { |
612 | 619 | $post_patch_commands.each | $cmd, $cmd_opts | { |
613 | | - exec { "Patching as Code - After patching - ${cmd}": |
| 620 | + exec { "Patching as Code - After patching - ${cmd}": # lint:ignore:exec_idempotency |
614 | 621 | * => delete($cmd_opts, ['require', 'schedule', 'tag']), |
615 | 622 | require => Anchor['patching_as_code::post'], |
616 | 623 | schedule => 'Patching as Code - Patch Window', |
|
620 | 627 | } |
621 | 628 | if ($high_prio_updates_to_install.count + $high_prio_choco_updates_to_install.count > 0) { |
622 | 629 | $post_patch_commands.each | $cmd, $cmd_opts | { |
623 | | - exec { "Patching as Code - After patching (High Priority)- ${cmd}": |
| 630 | + exec { "Patching as Code - After patching (High Priority)- ${cmd}": # lint:ignore:exec_idempotency |
624 | 631 | * => delete($cmd_opts, ['require', 'schedule', 'tag']), |
625 | 632 | require => Anchor['patching_as_code::post'], |
626 | 633 | schedule => 'Patching as Code - High Priority Patch Window', |
|
0 commit comments