Skip to content

Commit

Permalink
merge from dev
Browse files Browse the repository at this point in the history
  • Loading branch information
maschmann committed Sep 14, 2024
2 parents 139fa65 + 48cc93a commit 412aa58
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
9 changes: 6 additions & 3 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 Expand Up @@ -751,4 +754,4 @@ private function checkInventory(): void
$this->inventoryFile($inventory);
}
}
}
}

Check failure on line 757 in Asm/Ansible/Command/AnsiblePlaybook.php

View workflow job for this annotation

GitHub Actions / build (8.1, 10, phpunit-10.xml.dist)

Expected 1 newline at end of file; 0 found

Check failure on line 757 in Asm/Ansible/Command/AnsiblePlaybook.php

View workflow job for this annotation

GitHub Actions / build (8.2, 11, phpunit.xml.dist)

Expected 1 newline at end of file; 0 found

Check failure on line 757 in Asm/Ansible/Command/AnsiblePlaybook.php

View workflow job for this annotation

GitHub Actions / build (8.3, 11, phpunit.xml.dist)

Expected 1 newline at end of file; 0 found
4 changes: 2 additions & 2 deletions Tests/Asm/Ansible/Command/AnsiblePlaybookTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -732,11 +732,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 412aa58

Please sign in to comment.