Skip to content

Commit

Permalink
fix(plan): replace await with wait in add_inventory_hostnames
Browse files Browse the repository at this point in the history
- Change await to wait for better compatibility and readability
- Ensure all tasks complete before proceeding with the plan
  • Loading branch information
CoMfUcIoS committed Sep 19, 2024
1 parent ee47750 commit 11d0b54
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions spec/acceptance/peadm_spec/plans/add_inventory_hostnames.pp
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,21 @@
$t = get_targets('*')
wait_until_available($t)

$fqdn_results = wait(
parallelize($t) |$target| {
$fqdn = run_command('hostname -f', $target)
$target.set_var('certname', $fqdn.first['stdout'].chomp)
$fqdn_results = $t.map |$target| {
$fqdn = run_command('hostname -f', $target).first
if $fqdn['exit_code'] != 0 {
fail("Failed to get FQDN for target ${target.name}: ${fqdn['stderr']}")
}
)
$target.set_var('certname', $fqdn['stdout'].chomp)
}

$fqdn_results.each |$result| {
$command = "yq eval '(.groups[].targets[] | select(.uri == \"${result.target.uri}\").name) = \"${result.value}\"' -i ${inventory_file}"
$command = "yq eval '(.groups[].targets[] | select(.uri == \"${uri}\").name) = \"${certname}\"' -i ${inventory_file}"
$result = run_command($command, 'localhost').first
if $result['exit_code'] != 0 {
fail("Failed to update inventory file for target ${uri}: ${result['stderr']}")
}
$command = "yq eval '(.groups[].targets[] | select(.uri == \"${uri}\").name) = \"${certname}\"' -i ${inventory_file}"
run_command($command, 'localhost')
}
}

0 comments on commit 11d0b54

Please sign in to comment.