Run ad-hoc ansible commands against your vagrant box

OK, 4 years down the line, here’s my next pearl of wisdom. I’m not going to make statements about keeping this blog updated, because, as you can see, they generally fail :)

I’m working with vagrant boxes running on a VMware vsphere cluster (perhaps some details of that in a later blog post)..

I’d like to run “ansible -m setup” against it so that I can see what facts I can grab for a role.

First I tried this:

$ ansible -i .vagrant/provisioners/ansible/inventory/vagrant_ansible_inventory default -m ping

..but it failed with this message:

 default | UNREACHABLE! => {
    "changed": false,
    "msg": "Failed to connect to the host via ssh: Received disconnect from 10.1.1.1 port 22:2: Too many authentication failures\r\nAuthentication failed.\r\n",
    "unreachable": true
}

So, I attempted to debug by looking at what vagrant was doing when running vagrant ssh

$ export VAGRANT_LOG=debug
$ vagrant ssh

<snip LOTS and LOTS of output>

INFO ssh: Invoking SSH: ssh ["vagrant@10.1.1.1", "-p", "22", "-o", "LogLevel=FATAL", "-o", "Compression=yes", "-o", "DSAAuthentication=yes", "-o", "IdentitiesOnly=yes", "-o", "StrictHostKeyChecking=no", "-o", "UserKnownHostsFile=/dev/null", "-i", "/home/jerry/myansiblecode/.vagrant/machines/default/vsphere/private_key"]

..by selectively deleting the “-o” arguments until the ssh login failed, I found that the magic incantation was -o IdentitiesOnly=yes (I have many many private key files in ~/.ssh). But how to tell ansible to do this?

$ ansible -i /home/jerry/myansiblecode/.vagrant/provisioners/ansible/inventory/vagrant_ansible_inventory default --ssh-extra-args="-o IdentitiesOnly=yes" -m ping

default | SUCCESS => {
    "changed": false,
    "ping": "pong"
}

\0/

 
4
Kudos
 
4
Kudos

Now read this

DigitalOcean Vagrantfile

I was a bit besotted with being able to develop ansible code using an on-premise Vsphere cluster as a substrate. As I was developing a single-machine ELK stack for testing, I needed something a bit more beefy than virtualbox on my poor... Continue →