Skip to content

Failed to connect to the host via ssh: hostname contains invalid characters when using $playbook->inventory(...) #92

@Persaeus

Description

@Persaeus

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));

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions