Skip to content

Commit 957f060

Browse files
committed
refactor(peadm_spec): improve error handling in add_inventory_hostnames plan
- Replace parallelize with map for better readability - Add error handling for hostname command execution - Add error handling for inventory file update command
1 parent 46d5d6c commit 957f060

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

spec/acceptance/peadm_spec/plans/add_inventory_hostnames.pp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,15 @@
44
$t = get_targets('*')
55
wait_until_available($t)
66

7-
parallelize($t) |$target| {
8-
$fqdn = run_command('hostname -f', $target)
9-
$target.set_var('certname', $fqdn.first['stdout'].chomp)
10-
$command = "yq eval '(.groups[].targets[] | select(.uri == \"${target.uri}\").name) = \"${target.vars['certname']}\"' -i ${inventory_file}"
11-
run_command($command, 'localhost')
7+
$t.map |$target| {
8+
$fqdn = run_command('hostname -f', $target).first
9+
if $fqdn['exit_code'] != 0 {
10+
fail("Failed to get FQDN for target ${target.name}: ${fqdn['stderr']}")
11+
}
12+
$command = "yq eval '(.groups[].targets[] | select(.uri == \"${target.uri}\").name) = \"${fqdn['stdout'].chomp}\"' -i ${inventory_file}"
13+
$result = run_command($command, 'localhost').first
14+
if $result['exit_code'] != 0 {
15+
fail("Failed to update inventory file for target ${uri}: ${result['stderr']}")
16+
}
1217
}
1318
}

0 commit comments

Comments
 (0)