Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
maschmann committed Sep 14, 2024
2 parents 197fda4 + 30df141 commit 48cc93a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
7 changes: 5 additions & 2 deletions Asm/Ansible/Command/AnsiblePlaybook.php
Original file line number Diff line number Diff line change
Expand Up @@ -289,18 +289,21 @@ public function inventory(array $hosts = []): AnsiblePlaybookInterface
return $this;
}

// Wrapping each host in double quotes to avoid issues with spaces in host names.
$hosts = array_map(fn ($host) => sprintf('"%s"', $host), $hosts);

// In order to let ansible-playbook understand that the given option is a list of hosts, the list must end by
// comma "," if it contains just an entry. For example, supposing just a single host, "localhosts":
//
// Wrong: --inventory="locahost"
// Correct: --inventory="locahost,"
$hostList = implode(', ', $hosts);
$hostList = implode(',', $hosts);

if (count($hosts) === 1) {
$hostList .= ',';
}

$this->addOption('--inventory', sprintf('"%s"', $hostList));
$this->addOption('--inventory', $hostList);
$this->hasInventory = true;

return $this;
Expand Down
4 changes: 2 additions & 2 deletions Tests/Asm/Ansible/Command/AnsiblePlaybookTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -914,11 +914,11 @@ public function testInventory(): void
],
[
'input' => ['localhost'],
'expect' => '--inventory="localhost,"',
'expect' => '--inventory="localhost",',
],
[
'input' => ['localhost', 'host1'],
'expect' => '--inventory="localhost, host1"',
'expect' => '--inventory="localhost","host1"',
],

];
Expand Down

0 comments on commit 48cc93a

Please sign in to comment.