hashicorp / vagrant

Vagrant is a tool for building and distributing development environments.
https://www.vagrantup.com
Other
26.27k stars 4.43k forks source link

`ANSIBLE_SSH_ARGS` `-o IdentityFile=` option fails to quote path to private key and breaks on spaces #9597

Open JPvRiel opened 6 years ago

JPvRiel commented 6 years ago

Vagrant version

Vagrant 2.0.3

Host operating system

Ubuntu 16.04 LTS

Guest operating system

CentOS 7

Vagrantfile

Extract from my vagrant file.

  config.vm.provision 'ansible' do |ansible|
    ansible.playbook = 'common.yml'
      ansible.verbose = true
      ansible.inventory_path = 'inventories/dev/hosts.yml'
    end
  end

The Vagrantfile and the inventory file have been validated such that the static inventory matches the hosts defined in the vagrantfile

Debug output

Did not past full debug to gist. The relevant debug output is as follows (seen by invoking ansible.verbose = true

    <myhostname>.vagrant.test: Running ansible-playbook...
PYTHONUNBUFFERED=1 ANSIBLE_FORCE_COLOR=true ANSIBLE_HOST_KEY_CHECKING=false ANSIBLE_SSH_ARGS='-o UserKnownHostsFile=/dev/null -o IdentitiesOnly=yes -o IdentityFile=/home/<myuser>/<some path with a space>/ansible/.vagrant/machines/<myhostname>.vagrant.test/libvirt/private_key -o ControlMaster=auto -o ControlPersist=60s' ansible-playbook --connection=ssh --timeout=30 --extra-vars=ansible_user\=\'vagrant\' --limit="<myhostname>.vagrant.test" --inventory-file=inventories/dev/hosts.yml -v common.yml
Using /home/<myuser>/<some path with a space>/ansible/ansible.cfg as config file

PLAY [Common] ******************************************************************

TASK [Gathering Facts] *********************************************************
fatal: [<myhostname>.vagrant.test]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: ssh: Could not resolve hostname <part of directory name with a space>/ansible/.vagrant/machines/<myhostname>.vagrant.test/libvirt/private_key: Name or service not known\r\n", "unreachable": true}

Expected behavior

What should have happened?

SSH private key paths provided to ANSIBLE_SSH_ARGS are quoted to avoid issues with spaces

Actual behavior

What actually happened?

ANSIBLE_SSH_ARGS causes the play to break with {"changed": false, "msg": "Failed to connect to the host via ssh: ssh: Could not resolve hostname due to not quoting -o IdentityFile=<private key path with space>.

Steps to reproduce

  1. Run the ansible provisioner from an ansible project and Vagrant file that has a space in the parent path.
  2. Use ansible.verbose = true as a provisioner option to observe how -o IdentityFile= value was not safely quoted.

References

Related, but not identical

noaho commented 5 years ago

I have this issue too.