Run ansible playbook on vagrant machines

19 views
Skip to first unread message

Ravikumar Wagh

unread,
May 25, 2018, 10:51:54 PM5/25/18
to Ansible Project
Hello,

I wish to run a ansible playbook on vagrant machines. I know vagrant provisioning, but scenario how I wish to run is as below:

----------------
I have 3 vagrant machine in running state.

And I have ansible playbook, that I wish to run on these vagrant machines when machines are in running state. I mean I wish run playbook by running ansible command to configure vagrant machines without use of command vagrant up.

When I run ansible command ansible facing issue to ssh. Because vagrant machine forwards guests 22 port on different port on host as follows

machine1 22=> 2201
machine2 22=> 2202
machine3 22=> 2203

As we know ansible works on ssh port that is 22. I know we can configure ansible to use another port lets say 2201, but what about other 2 machines running on port 2202 and 2203.
----------------

Thanks !!!

Kai Stian Olstad

unread,
May 26, 2018, 2:41:31 AM5/26/18
to ansible...@googlegroups.com
On 26.05.2018 04:51, Ravikumar Wagh wrote:
> When I run ansible command ansible facing issue to ssh. Because vagrant
> machine forwards guests 22 port on different port on host as follows
>
> machine1 22=> 2201
> machine2 22=> 2202
> machine3 22=> 2203
>
> As we know ansible works on ssh port that is 22. I know we can
> configure
> ansible to use another port lets say 2201, but what about other 2
> machines
> running on port 2202 and 2203.

ansible_ssh_port

https://docs.ansible.com/ansible/2.5/scenario_guides/guide_vagrant.html#running-ansible-manually

--
Kai Stian Olstad

js.a

unread,
Jun 6, 2018, 11:06:15 PM6/6/18
to Ansible Project
Hello Ravikumar.

I don't need to be concerned about which ssh port Vagrant is actually using to connect to VMs. Just set up correctly an Ansible's inventory file passing the credentials for the connection, VM's IP and names. I have the same scenario you described and everything that I've done was:

# inventory file 

IPs and names..
....

Groups
...

# Setting up management connections to hosts
[all:vars]
ansible_ssh_user=vagrant
ansible_ssh_private_key_file=/root/.vagrant.d/insecure_private_key
ansible_ssh_common_args='-o StrictHostKeyChecking=no'

[user@testenv ~] sudo ansible-playbook -i inventory_file _your_playbook_file

Of course, it's a default configuration for testing and controlled environments.

Good luck.
j.
___________________________________
Reply all
Reply to author
Forward
0 new messages