Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Persaeus opened this issue Jan 24, 2024 · 2 comments
Assignees
Labels

Comments

@Persaeus
Copy link

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));
@maschmann
Copy link
Owner

Hi @Persaeus - just to clarify: What kind of system did you run ansible on, so I can try to replicate?

@Persaeus
Copy link
Author

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

@maschmann maschmann added the bug label Feb 12, 2024
@maschmann maschmann self-assigned this Feb 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants