Very confused Vagrant/Ansible

Hey,

I am probably missing something very obvious, but here is my situation

I use Vagrant to spin up some VMs, to make it easy, it is like this:

ansible VM
host1 VM
host2 VM
hostN VM

My goal is that I want ansible installed on the ansible VM within Vagrant (virtualbox), and I want to kick off my playbook and have ansible install all the goodies on host1-n.

So, what works, is that ansible gets installed and runs, very simple to do there, what doesn’t work is connecting to any of the other Vagrant VMs with

fatal: [192.168.50.101]: UNREACHABLE! => {“changed”: false, “msg”: “Failed to connect to the host via ssh.”, “unreachable”: true}

I have exactly no idea what I am doing wrong here, but obviously it is something with ssh :slight_smile: I have tried using the private_key from the virtualmachine in a place where ansible can see it, and creating a host_vars directory with files like

filename: 192.168.50.20
content: ansible_ssh_private_key_file: /home/vargrant/sync/.vagrant/machines/host1/virtualbox/private_key

but alas, that doesn’t work either. Any help would be greatly appreciated as I have hit a brick wall.

To note, my ansible playbook works fine on the vm it is running on, named “ansible”, just can’t connect to the other vms, even though I can ping them and ssh to them manually using the standard vagrant username/pass from within the ansible machine

I don't know vagrant, but which username is ansible running as on the ansible machine, and which username did you use to connect to the other hosts? If it is not the same you need to tell ansible to use that other username, there are several ways of doing that from the command line, inventory or even config file.

I hope that this helps

@Greg - Have a look at my Vagrant box templates which include using Ansible for all provisioning. May be able to get you headed down the right path.

https://github.com/mrlesmithjr/vagrant-box-templates

Specifically bootstrap.yml