# Ansible - To limit the execution for the range of hosts

**URL:** <https://forum.ansible.com/t/ansible-to-limit-the-execution-for-the-range-of-hosts/30658>\
**Category:** Ansible Project\
**Created:** [June 26, 2019, 11:02am UTC](https://forum.ansible.com/t/ansible-to-limit-the-execution-for-the-range-of-hosts/30658 "2019-06-26T11:02:25Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Preethi\_Muruganantha](https://avatars.discourse-cdn.com/v4/letter/p/df788c/32.png) [@Preethi\_Muruganantha](https://forum.ansible.com/u/Preethi_Muruganantha)\
**Post date:** [June 26, 2019, 11:02am UTC](https://forum.ansible.com/t/ansible-to-limit-the-execution-for-the-range-of-hosts/30658/1 "2019-06-26T11:02:25Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Preethi\_Muruganantha](https://avatars.discourse-cdn.com/v4/letter/p/df788c/32.png) [@Preethi\_Muruganantha](https://forum.ansible.com/u/Preethi_Muruganantha)\
**Post date:** [June 26, 2019, 11:05am UTC](https://forum.ansible.com/t/ansible-to-limit-the-execution-for-the-range-of-hosts/30658/2 "2019-06-26T11:05:22Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![Tchia04](https://avatars.discourse-cdn.com/v4/letter/t/fbc32d/32.png) [@Tchia04](https://forum.ansible.com/u/Tchia04)\
**Post date:** [June 26, 2019, 6:24pm UTC](https://forum.ansible.com/t/ansible-to-limit-the-execution-for-the-range-of-hosts/30658/3 "2019-06-26T18:24:53Z")

</div>

You can get the current executing ip addresses in the playbook using the magic variable inventory\_hostname

You can find more information at  
[https://docs.ansible.com/ansible/latest/user\_guide/playbooks\_variables.html#magic-variables-and-how-to-access-information-about-other-hosts](https://docs.ansible.com/ansible/latest/user_guide/playbooks_variables.html#magic-variables-and-how-to-access-information-about-other-hosts)

---

<div class="post-metadata">

**Author:** ![Preethi\_Muruganantha](https://avatars.discourse-cdn.com/v4/letter/p/df788c/32.png) [@Preethi\_Muruganantha](https://forum.ansible.com/u/Preethi_Muruganantha)\
**Post date:** [June 27, 2019, 9:01am UTC](https://forum.ansible.com/t/ansible-to-limit-the-execution-for-the-range-of-hosts/30658/4 "2019-06-27T09:01:08Z")

</div>

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)
