Fixing SSH unknown error when provisioning a Vagrant VM with Ansible

While getting a local VM managed by Vagrant to work with Ansible for provisioning, I kept getting errors like the following:

<br />
fatal: [solr] =&gt; 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

[vm-name-here] : ok=0 changed=0 unreachable=1 failed=0

FATAL: no hosts matched or all hosts have already failed -- aborting

Ansible failed to complete successfully. Any error output should be
visible above. Please fix these errors and try again.

It seems that Ansible is unable to connect to the VirtualBox host via SSH because the entry for in my ~/.ssh/known-hosts file is set for my local computer, and not for any VMs. To work around this limitation, I created a new file, ~/.ssh/config, with the contents:

<br />
Host<br />
        StrictHostKeyChecking no<br />
        UserKnownHostsFile=/dev/null<br />

Now, when Ansible tries connecting during provisioning, it doesn't check the host key for localhost, and provisioning succeeds.


Thank you so much for this advise, it was really helpful!

In my case I had to add this line to get it working:
IdentitiesOnly yes

Thanks! I think this finally got it working for me.

how do you tell ansible to use your new config file?