When building out a Vagrant project it would be helpful to run ad hoc Ansible tasks instead of adding test commands to a playbook. I've tried several methods of targeting the VM but keep getting this error:
default | FAILED => SSH encountered an unknown error during the connection. We
recommend you re-run the command using -vvvv, which will enable SSH debugging
output to help diagnose the issue
I'm using the Vagrant generated Ansible inventory file and the box has a working hostname. How do I target my Vagrant VM with a single Ansible task?
I was missing Vagrant's private ssh key. Found that here: stackoverflow.com/a/18943360/503463
There are a couple ways to do this, but here's what I'm using:
ansible all -i vagrant_ansible_inventory_default -u vagrant --private-key ~/.vagrant.d/insecure_private_key -m ping
Everything before -m
is essentially boilerplate. I'm using a standard box with the default username 'vagrant'. The flag -i vagrant_ansible_inventory_default
tells Ansible to use the inventory file generated by Vagrant; it contains one host, so targeting all
is safe ('default' also works). Finally, we pass the Vagrant private key to authenticate the ssh connection: --private-key ~/.vagrant.d/insecure_private_key
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With