# How to i get list of all hosts in playbook\_on\_task\_start ?

**URL:** <https://forum.ansible.com/t/how-to-i-get-list-of-all-hosts-in-playbook-on-task-start/21269>\
**Category:** Ansible Project\
**Created:** [April 25, 2016, 8:17pm UTC](https://forum.ansible.com/t/how-to-i-get-list-of-all-hosts-in-playbook-on-task-start/21269 "2016-04-25T20:17:16Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ritesh\_Shetty](https://avatars.discourse-cdn.com/v4/letter/r/839c29/32.png) [@Ritesh\_Shetty](https://forum.ansible.com/u/Ritesh_Shetty)\
**Post date:** [April 25, 2016, 8:17pm UTC](https://forum.ansible.com/t/how-to-i-get-list-of-all-hosts-in-playbook-on-task-start/21269/1 "2016-04-25T20:17:16Z")

</div>

I used to have this code in ansible 1.x

---

<div class="post-metadata">

**Author:** ![Ritesh\_Shetty](https://avatars.discourse-cdn.com/v4/letter/r/839c29/32.png) [@Ritesh\_Shetty](https://forum.ansible.com/u/Ritesh_Shetty)\
**Post date:** [April 26, 2016, 2:38am UTC](https://forum.ansible.com/t/how-to-i-get-list-of-all-hosts-in-playbook-on-task-start/21269/2 "2016-04-26T02:38:35Z")

</div>

play.hosts works !

---

<div class="post-metadata">

**Author:** ![Ritesh\_Shetty](https://avatars.discourse-cdn.com/v4/letter/r/839c29/32.png) [@Ritesh\_Shetty](https://forum.ansible.com/u/Ritesh_Shetty)\
**Post date:** [June 3, 2016, 1:50am UTC](https://forum.ansible.com/t/how-to-i-get-list-of-all-hosts-in-playbook-on-task-start/21269/3 "2016-06-03T01:50:54Z")

</div>

there is a problem to this …

if my hostvars declared esx\_host and under that the host is lets say 10.16.1.3 then self.play.hosts gives esx\_host and not 10.16.1.3

```auto
runner_on_ok gets the right host as a parameter

```

So back to finding a good way ! I am using ansible 1.0 and alos using the adaptors as recommended

```auto
def v2_playbook_on_task_start(self, task, is_conditional):
    self.task = task
    self.playbook_on_task_start(task, is_conditional)

```
