From 5c0f087b649b9c820e14f9cffe838505dbf0ee2a Mon Sep 17 00:00:00 2001 From: Robert Waffen Date: Thu, 5 Mar 2026 11:35:54 +0100 Subject: [PATCH 1/5] fix: only map names if arrays are not empty --- plans/patch_batch.pp | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/plans/patch_batch.pp b/plans/patch_batch.pp index 707f972..f21f002 100644 --- a/plans/patch_batch.pp +++ b/plans/patch_batch.pp @@ -85,22 +85,31 @@ out::message($patching_result) } - $no_patches = $patching_result.ok_set.filter |$item| { - $item.value['packages_updated'].empty - }.map |$n| { $n.name }.sort + $_no_patches = $patching_result.ok_set.filter |$item| { $item.value['packages_updated'].empty } + $no_patches = if empty($_no_patches) { + [] + } else { + $_no_patches.map |$n| { $n.name }.sort + } - $with_patches = $patching_result.ok_set.filter |$item| { - ! $item.value['packages_updated'].empty - }.map |$n| { $n.name }.sort + $_with_patches = $patching_result.ok_set.filter |$item| { ! $item.value['packages_updated'].empty } + $with_patches = if empty($_with_patches) { + [] + } else { + $_with_patches.map |$n| { $n.name }.sort + } - $reboot_required = $patching_result.ok_set.filter |$item| { - $item.value['reboot_required'] == true - }.map |$n| { $n.name }.sort + $_reboot_required = $patching_result.ok_set.filter |$item| { $item.value['reboot_required'] == true } + $reboot_required = if empty($_reboot_required) { + [] + } else { + $_reboot_required.map |$n| { $n.name }.sort + } $targets = get_targets($batch).map |$t| { $t.name }.sort $output = { - failed => $patching_result.error_set.map |$n| { $n.name }.sort, + failed => $patching_result.error_set.names.sort, health_check => $run_health_check, health_check_failed => $health_check_failed, no_patches => $no_patches, From 1aa8c1e71a30d0f2ed768f8656825ee5ab2c991b Mon Sep 17 00:00:00 2001 From: Robert Waffen Date: Thu, 5 Mar 2026 11:39:34 +0100 Subject: [PATCH 2/5] test: log no_patches before mapping names --- plans/patch_batch.pp | 1 + 1 file changed, 1 insertion(+) diff --git a/plans/patch_batch.pp b/plans/patch_batch.pp index f21f002..0bcd851 100644 --- a/plans/patch_batch.pp +++ b/plans/patch_batch.pp @@ -89,6 +89,7 @@ $no_patches = if empty($_no_patches) { [] } else { + out::message($_no_patches) $_no_patches.map |$n| { $n.name }.sort } From 8c32ad450da6fc4b418e3cb4483a1ebc0b773b23 Mon Sep 17 00:00:00 2001 From: Robert Waffen Date: Thu, 5 Mar 2026 11:45:13 +0100 Subject: [PATCH 3/5] fix: simplify result handling by using names directly --- plans/patch_batch.pp | 28 +++++----------------------- 1 file changed, 5 insertions(+), 23 deletions(-) diff --git a/plans/patch_batch.pp b/plans/patch_batch.pp index 0bcd851..970f268 100644 --- a/plans/patch_batch.pp +++ b/plans/patch_batch.pp @@ -56,7 +56,7 @@ # get nodes that are 'clean' from health check results $nodes_to_patch = ($health_checks.filter_set |$item| { $item.value['state'] == 'clean' }).map |$n| { $n.target } - $health_check_failed = ($health_checks.filter_set |$item| { $item.status == 'failure' }).map |$n| { $n.name }.sort + $health_check_failed = ($health_checks.filter_set |$item| { $item.status == 'failure' }).names if $debug { out::message('patch_batch.pp: Nodes to patch after health check:') @@ -85,32 +85,14 @@ out::message($patching_result) } - $_no_patches = $patching_result.ok_set.filter |$item| { $item.value['packages_updated'].empty } - $no_patches = if empty($_no_patches) { - [] - } else { - out::message($_no_patches) - $_no_patches.map |$n| { $n.name }.sort - } - - $_with_patches = $patching_result.ok_set.filter |$item| { ! $item.value['packages_updated'].empty } - $with_patches = if empty($_with_patches) { - [] - } else { - $_with_patches.map |$n| { $n.name }.sort - } - - $_reboot_required = $patching_result.ok_set.filter |$item| { $item.value['reboot_required'] == true } - $reboot_required = if empty($_reboot_required) { - [] - } else { - $_reboot_required.map |$n| { $n.name }.sort - } + $no_patches = $patching_result.ok_set.filter_set |$item| { $item.value['packages_updated'].empty }.names + $with_patches = $patching_result.ok_set.filter_set |$item| { ! $item.value['packages_updated'].empty }.names + $reboot_required = $patching_result.ok_set.filter_set |$item| { $item.value['reboot_required'] == true }.names $targets = get_targets($batch).map |$t| { $t.name }.sort $output = { - failed => $patching_result.error_set.names.sort, + failed => $patching_result.error_set.names, health_check => $run_health_check, health_check_failed => $health_check_failed, no_patches => $no_patches, From b41395b14b5ce213c7b3d3002db01dbc9a105f88 Mon Sep 17 00:00:00 2001 From: Robert Waffen Date: Thu, 5 Mar 2026 12:07:00 +0100 Subject: [PATCH 4/5] fix: add debug logging for patching results and health check status --- plans/patch_batch.pp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/plans/patch_batch.pp b/plans/patch_batch.pp index 970f268..605ea64 100644 --- a/plans/patch_batch.pp +++ b/plans/patch_batch.pp @@ -89,6 +89,12 @@ $with_patches = $patching_result.ok_set.filter_set |$item| { ! $item.value['packages_updated'].empty }.names $reboot_required = $patching_result.ok_set.filter_set |$item| { $item.value['reboot_required'] == true }.names + if $debug { + out::message(type($no_patches)) + out::message(type($with_patches)) + out::message(type($reboot_required)) + out::message(type($health_check_failed)) + } $targets = get_targets($batch).map |$t| { $t.name }.sort $output = { From 7fdc2075d8ac54cb3e6612a750d8c0f363b1ecd2 Mon Sep 17 00:00:00 2001 From: Robert Waffen Date: Thu, 5 Mar 2026 12:12:28 +0100 Subject: [PATCH 5/5] fix: remove debug logging for patching results in patch_batch plan --- plans/patch_batch.pp | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/plans/patch_batch.pp b/plans/patch_batch.pp index 605ea64..fbd374d 100644 --- a/plans/patch_batch.pp +++ b/plans/patch_batch.pp @@ -88,14 +88,7 @@ $no_patches = $patching_result.ok_set.filter_set |$item| { $item.value['packages_updated'].empty }.names $with_patches = $patching_result.ok_set.filter_set |$item| { ! $item.value['packages_updated'].empty }.names $reboot_required = $patching_result.ok_set.filter_set |$item| { $item.value['reboot_required'] == true }.names - - if $debug { - out::message(type($no_patches)) - out::message(type($with_patches)) - out::message(type($reboot_required)) - out::message(type($health_check_failed)) - } - $targets = get_targets($batch).map |$t| { $t.name }.sort + $targets = get_targets($batch).map |$t| { $t.name }.sort $output = { failed => $patching_result.error_set.names,