|
| 1 | +# @summary Patch nodes in a batch |
| 2 | +# |
| 3 | +plan os_patching::patch_batch ( |
| 4 | + Array $batch = [], |
| 5 | + Boolean $catch_errors = true, |
| 6 | + Boolean $noop_state = false, |
| 7 | + Boolean $run_health_check = false, |
| 8 | + Boolean $service_enabled = true, |
| 9 | + Boolean $service_running = true, |
| 10 | + Integer $runinterval = 1800, |
| 11 | +) { |
| 12 | + out::message("patch_batch.pp: Patching batch of nodes: ${batch}") |
| 13 | + |
| 14 | + $targets = get_targets($batch) |
| 15 | + |
| 16 | + if $run_health_check { |
| 17 | + out::message('patch_batch.pp: Running health check before patching') |
| 18 | + run_task('os_patching::health_check', $targets, |
| 19 | + _catch_errors => $catch_errors, |
| 20 | + target_noop_state => $noop_state, |
| 21 | + target_runinterval => $runinterval, |
| 22 | + target_service_enabled => $service_enabled, |
| 23 | + target_service_running => $service_running, |
| 24 | + ) |
| 25 | + |
| 26 | + $nodes_to_patch = $health_checks.filter | $items | { $items.value['state'] == 'clean' } |
| 27 | + $nodes_skipped = $health_checks.filter | $items | { $items.value['state'] != 'clean' } |
| 28 | + |
| 29 | + $skipped_nodes = $nodes_skipped.map | $value | { $value['certname'] } |
| 30 | + $patchable_nodes = $nodes_to_patch.map | $value | { $value['certname'] } |
| 31 | + |
| 32 | + $task_result = run_task('os_patching::patch_server', $patchable_nodes, |
| 33 | + _catch_errors => $catch_errors, |
| 34 | + ) |
| 35 | + |
| 36 | + $successful_patched_nodes = $task_result.ok_set.names |
| 37 | + $failed_patched_nodes = $task_result.error_set.names |
| 38 | + } else { |
| 39 | + out::message('patch_batch.pp: Health check is disabled.') |
| 40 | + $task_result = run_task('os_patching::patch_server', $targets, |
| 41 | + _catch_errors => $catch_errors, |
| 42 | + ) |
| 43 | + |
| 44 | + log::debug("patch_batch.pp: Patching task result for ${targets}: ${task_result}") |
| 45 | + |
| 46 | + $successful_patched_nodes = $task_result.ok_set.names |
| 47 | + $failed_patched_nodes = $task_result.error_set.names |
| 48 | + $skipped_nodes = [] # No skipped nodes if health check is not run |
| 49 | + } |
| 50 | + |
| 51 | + return( |
| 52 | + { |
| 53 | + targets => $targets, |
| 54 | + patched => $successful_patched_nodes, |
| 55 | + failed => $failed_patched_nodes, |
| 56 | + skipped => $skipped_nodes, |
| 57 | + health_check => $run_health_check, |
| 58 | + } |
| 59 | + ) |
| 60 | +} |
0 commit comments