Typically, you can use ssh in a managed Vagrant VM using vagrant ssh . There are two options:
- You can use the
insecure_private_key generated by Vagrant for authentication. - Use your own private key - provided that
config.ssh.forward_agent set to true and the VM is configured correctly
I am using the second option. S, when I run vagrant ssh , I ssh to the machine using my personal private key.
Now I need to provide Ansible SSH to my vagrant machine, and I don't want to use Vagrantfile for it.
So, I did:
ansible-playbook -i hosts/development --private-key=~/.ssh/id_rsa -u vagrant dev.yml
And I have this error:
fatal: [192.168.50.5] => SSH error: permission denied (publicickey). when connected to 192.168.50.5:22
The hosts/inventory contains only the IP of my Vagrant VM (192.168.50.5).
I do not know why Ansible cannot ssh in VM. It uses the exact same user ( vagrant ) and the key ( id_rsa ) as when executing vagrant ssh .
However, there is no problem with sshing with vagrant ssh , while the above will not work.
Any suggestions would be highly appreciated.
vagrant ssh ansible
luqo33
source share