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:
|
$this->addOption('--inventory', sprintf('"%s"', $hostList)); |
Should be changed to:
$this->addOption('--inventory', sprintf('%s', $hostList));