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 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@", "-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"] 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"



Now read this

My obligatory Ubuntu ssh-agent post

There has been much wailing and gnashing of teeth regarding the default SSH/GPG agent in Ubuntu (the GNOME 3 “Passwords & Keys” app). It has several shortcomings and lacks some of the functionality that the standard tools have. There... Continue →