Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run ad hoc Ansible commands in Vagrant?

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?

like image 841
joemaller Avatar asked Oct 11 '13 22:10

joemaller


1 Answers

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

like image 156
joemaller Avatar answered Oct 07 '22 12:10

joemaller