Search code examples
sshvagrantansiblevirtualboxpermission-denied

Ansible "Failed to connect to the host via ssh


I am working with VirtualBox, Vagrant and Ansible. It worked fine until I ran

ssh [email protected]

and got the following output:

The authenticity of host '10.10.10.10 (10.10.10.10)' can't be established.
ECDSA key fingerprint is
SHA256:IIbQq8qenKqUEpurYCMbbaRBCHXEgWK4Br7KSusmyw4.
Are you sure you want to continue connecting (yes/no)?

I typed "yes", and since then every time I type vagrant provision, I keep getting:

fatal: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: Warning: Permanently added '10.10.10.10' (ECDSA) to the list of known hosts.\r\nPermission denied ().\r\n", "unreachable": true}

I then removed the generated key from ~/.ssh/known_hosts, but I keep getting the same error.


Solution

  • After a ton of time searching for the answer I found the solution that worked for me. I added the following few lines to my Vagrantfile and reloaded vm

    ansible.raw_arguments = [
    "--private-key=~/path/to/.vagrant/machines/default/virtualbox/private_key"
    ]