php-ansible icon indicating copy to clipboard operation
php-ansible copied to clipboard

Add quotes around each host in inventory

Open bambamboole opened this issue 1 year ago • 3 comments

This PR "fixes" how the inventory is parsed.

Before it has surrounded the comma delimited hosts with double quotes. For me this ended up in something like:

ANSIBLE_HOST_KEY_CHECKING='False' 'ansible-playbook' 'general.yml' '--private-key=/Users/user_name/Projects/private/server/storage/app/ssh_keys/01GZ920GJKRZTWQ6DBD0Z623FN' '--user=user_name' '--inventory="111.92.169.113,"'

But Ansible can't connect to the host by having it formatted like this. Adding quotes arounf each host resolves the issue for me:

ANSIBLE_HOST_KEY_CHECKING='False' 'ansible-playbook' 'general.yml' '--private-key=/Users/user_name/Projects/private/server/storage/app/ssh_keys/01GZ920GJKRZTWQ6DBD0Z623FN' '--user=user_name' '--inventory="111.92.169.113",'

~~This could be an issue for host names with spaces in it, or what do you think?~~

I changed it to wrap each host with quotes. I think this should solve both cases :)

bambamboole avatar Apr 30 '23 12:04 bambamboole

Hi :-) We really added the double quotes to be able to use spaces in hostnames. For some instances, like e.g. AWS VM names, spaces might be present in hostnames. On the other hand, if present, double quotes do no harm to the hostlist string.

Not sure what breaks the host list, though: What OS did you test it on and also with which Ansible version? might be the combination of "," with the quotes.

maschmann avatar Apr 30 '23 13:04 maschmann

I am developing on macOS and use one of the latest versions of Ansible. Not at home currently, but can check later. Would you accept the PR if I extend it and add quotes to hosts containing spaces?

bambamboole avatar Apr 30 '23 14:04 bambamboole

@maschmann I updated the PR to facilitate hosts with spaces in it.

bambamboole avatar Apr 30 '23 16:04 bambamboole