Normally, you can ssh into a Vagrant-managed VM with vagrant ssh
. There are two options:
insecure_private_key
generated by
I think that you should try using the inventory generated by vagrant. This will save you from having to maintain an Ansible inventory in addition to your Vagrantfile.
For example, you should find an inventory like this used for vagrant ssh
:
cat .vagrant/provisioners/ansible/inventory/vagrant_ansible_inventory
>>>
# Generated by Vagrant
default ansible_host=127.0.0.1 ansible_port=2222 ansible_user='vagrant' ansible_ssh_private_key_file='/home/someone/coding-in-a-project/.vagrant/machines/default/virtualbox/private_key'
You will be able to run ansible
ad-hoc commands and ansible-playbook
commands.
(specify this maybe for your needs : --private-key=~/.ssh/your_private_key
)
ansible default -i .vagrant/provisioners/ansible/inventory/vagrant_ansible_inventory -m ansible.builtin.shell -a 'echo foobar'
ansible-playbook -i .vagrant/provisioners/ansible/inventory/vagrant_ansible_inventory playbook.yml
source : https://docs.ansible.com/ansible/latest/scenario_guides/guide_vagrant.html