Normally, you can ssh into a Vagrant-managed VM with vagrant ssh
. There are two options:
- You can use an
insecure_private_key
generated by Vagrant to authenticate. - Use your own private key - provided that
config.ssh.forward_agent
is set totrue
, and the VM is configured correctly
I use the second option. S when I run vagrant ssh
, I ssh into the machine with my custom private key.
Now I need to let Ansible SSH into my Vagrant machine and I do not want to use Vagrantfile
for it.
So I executed:
ansible-playbook -i hosts/development --private-key=~/.ssh/id_rsa -u vagrant dev.yml
And I have this error returned:
fatal: [192.168.50.5] => SSH Error: Permission denied (publickey). while connecting to 192.168.50.5:22
The hosts/inventory
file holds just the IP of my Vagrant VM (192.168.50.5).
I do not know why Ansible cannot ssh into the VM. It's using exactly the same user (vagrant
) and key (id_rsa
) as when executing vagrant ssh
.
However, there is no problem sshing with vagrant ssh
while the above would not run.
Any suggestions would be much appreciated.