# variable for list of targetted hosts

**URL:** <https://forum.ansible.com/t/variable-for-list-of-targetted-hosts/20921>\
**Category:** Ansible Project\
**Created:** [March 18, 2016, 3:54pm UTC](https://forum.ansible.com/t/variable-for-list-of-targetted-hosts/20921 "2016-03-18T15:54:04Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jocelyn\_gibart](https://avatars.discourse-cdn.com/v4/letter/j/67e7ee/32.png) [@jocelyn\_gibart](https://forum.ansible.com/u/jocelyn_gibart)\
**Post date:** [March 18, 2016, 3:54pm UTC](https://forum.ansible.com/t/variable-for-list-of-targetted-hosts/20921/1 "2016-03-18T15:54:04Z")

</div>

Hello dear Ansible wizards

Is there a way to get the list of targetted hosts for a playbook or for a role ?

I didnt find any variable or any way to get this.

What I’m looking for is not merely the hosts: value, it is the intersection of hosts values and -l ( --limit ) option.

Thank you

---

<div class="post-metadata">

**Author:** ![Arthur\_Reyes](https://avatars.discourse-cdn.com/v4/letter/a/90ced4/32.png) [@Arthur\_Reyes](https://forum.ansible.com/u/Arthur_Reyes)\
**Post date:** [March 18, 2016, 8:04pm UTC](https://forum.ansible.com/t/variable-for-list-of-targetted-hosts/20921/2 "2016-03-18T20:04:36Z")

</div>

$ ansible -i INVENTORY all -m setup --limit vm04 --list-hosts

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [March 18, 2016, 8:26pm UTC](https://forum.ansible.com/t/variable-for-list-of-targetted-hosts/20921/3 "2016-03-18T20:26:58Z")

</div>

the play\_hosts var should have that list (unless you are using serial, which limits it per batch)

---

<div class="post-metadata">

**Author:** ![jocelyn\_gibart](https://avatars.discourse-cdn.com/v4/letter/j/67e7ee/32.png) [@jocelyn\_gibart](https://forum.ansible.com/u/jocelyn_gibart)\
**Post date:** [March 21, 2016, 8:43am UTC](https://forum.ansible.com/t/variable-for-list-of-targetted-hosts/20921/4 "2016-03-21T08:43:31Z")

</div>

Yes,it is working, thanks.  
This is exactly what I was looking for.
