Ansible - To limit the execution for the range of hosts

120 views
Skip to first unread message

Preethi Muruganantham

unread,
Jun 26, 2019, 7:02:25 AM6/26/19
to Ansible Project
Can you give me a suggestion about one more requirement?
I need to limit the playbook execution for particular hosts.
Eg., From host1 to the host mentioned in site.retry file

My inventory file:

192.168.11.1
192.168.11.2
192.168.11.3

Playbook name: site.yml
Command: ansible-playbook site.yml  --limit @~/site.retry)

The above command executes the playbook only for the host present in site.retry file.
But I need to execute the playbook from host1 until the host present in site.retry file.

For eg., if site.retry file contains - 192.168.11.2
I need the playbook to run for 192.168.11.1 and 192.168.11.2  (ie., from the host1 till the one mentioned in site.retry file)

Is there any way to achieve this?

Preethi Muruganantham

unread,
Jun 26, 2019, 7:05:22 AM6/26/19
to Ansible Project
Or is there any way in ansible to fetch the IP of the hosts where the playbooks are executed? 
As like .retry file in ansible which holds the IP of failed one, is there any ways in ansible which holds the IPs of all executed hosts alone(ie., hosts in which the playbook executes)

Tony Chia

unread,
Jun 26, 2019, 2:24:53 PM6/26/19
to Ansible Project
You can get the current executing ip addresses in the playbook using the magic variable inventory_hostname

Preethi Muruganantham

unread,
Jun 27, 2019, 5:01:10 AM6/27/19
to Ansible Project
Yes, I can get the current target host IP using "inventory_hostname". But the problem is I have to store that IP in a local file in my master machine (ie., where the ansible runs)
Reply all
Reply to author
Forward
0 new messages