Skip to content

Commit 801a41c

Browse files
committed
fix(plan): streamline add_inventory_hostnames by removing redundant code
- Remove redundant set_var calls for certname - Combine yq command execution within the target mapping loop - Ensure inventory file is updated correctly for each target
1 parent 11d0b54 commit 801a41c

File tree

1 file changed

+2
-8
lines changed

1 file changed

+2
-8
lines changed

spec/acceptance/peadm_spec/plans/add_inventory_hostnames.pp

+2-8
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,15 @@
44
$t = get_targets('*')
55
wait_until_available($t)
66

7-
$fqdn_results = $t.map |$target| {
7+
$t.map |$target| {
88
$fqdn = run_command('hostname -f', $target).first
99
if $fqdn['exit_code'] != 0 {
1010
fail("Failed to get FQDN for target ${target.name}: ${fqdn['stderr']}")
1111
}
12-
$target.set_var('certname', $fqdn['stdout'].chomp)
13-
}
14-
15-
$fqdn_results.each |$result| {
16-
$command = "yq eval '(.groups[].targets[] | select(.uri == \"${uri}\").name) = \"${certname}\"' -i ${inventory_file}"
12+
$command = "yq eval '(.groups[].targets[] | select(.uri == \"${target.uri}\").name) = \"${fqdn['stdout'].chomp}\"' -i ${inventory_file}"
1713
$result = run_command($command, 'localhost').first
1814
if $result['exit_code'] != 0 {
1915
fail("Failed to update inventory file for target ${uri}: ${result['stderr']}")
2016
}
21-
$command = "yq eval '(.groups[].targets[] | select(.uri == \"${uri}\").name) = \"${certname}\"' -i ${inventory_file}"
22-
run_command($command, 'localhost')
2317
}
2418
}

0 commit comments

Comments
 (0)