`Failed to connect to the host via ssh: hostname contains invalid characters` when using `$playbook->inventory(...)`
Persaeus opened this issue · 2 comments
Persaeus commented
ansible-playbook [core 2.15.8]
$ansible = (new Ansible())->playbook()->inventory(['foo.local']);
The above example fails with the following error:
fatal: ["foo.local]: UNREACHABLE! => {
"changed": false,
"msg": "Failed to connect to the host via ssh: hostname contains invalid characters",
"unreachable": true
}
Looking through the logs, it appears the --inventory
option is added using incorrect format:
'ansible-playbook' 'playbook.yml' '--inventory="foo.local,"'
Removing the double-quotes around the hostname fixes the connection issue:
Should be changed to:
$this->addOption('--inventory', sprintf('%s', $hostList));
maschmann commented
Hi @Persaeus - just to clarify: What kind of system did you run ansible on, so I can try to replicate?
Persaeus commented
Hi @maschmann. I encountered this inside a Docker container built using ubuntu:22.04
on aarch64
, PHP 8.3.2
.
My current workaround looks like this (using spatie/invade
to access private method addOption
):
invade($playbook)->addOption('--inventory', sprintf('%s', "$ipAddress,"));