# callback\_plugin: get list of hosts in \_\_init\_\_

**URL:** <https://forum.ansible.com/t/callback-plugin-get-list-of-hosts-in-init/26775>\
**Category:** Ansible Developer\
**Created:** [February 18, 2018, 5:18am UTC](https://forum.ansible.com/t/callback-plugin-get-list-of-hosts-in-init/26775 "2018-02-18T05:18:36Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![senorsmile](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/senorsmile/32/9024_2.png) [@senorsmile](https://forum.ansible.com/u/senorsmile)\
**Post date:** [February 18, 2018, 5:18am UTC](https://forum.ansible.com/t/callback-plugin-get-list-of-hosts-in-init/26775/1 "2018-02-18T05:18:36Z")

</div>

I am developing a custom callback plugin.

I need to know the computed list of hosts in the constructor (i.e. the \_\_init\_\_method of my CallbackModule).  
This should be all hosts currently limited, not necessarily which hosts will actually be called in any particular play (which may vary of course).

Is this even possible to grab at that point?

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [February 19, 2018, 2:36pm UTC](https://forum.ansible.com/t/callback-plugin-get-list-of-hosts-in-init/26775/2 "2018-02-19T14:36:02Z")

</div>

The earliest you can start to get info like that is during `v2_playbook_on_play_start`

` __init__ ` is run during object instantiation, which happens before a playbook and play have been parsed. Since a play is where the hosts live, you will have to wait until that point.

---

<div class="post-metadata">

**Author:** ![senorsmile](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/senorsmile/32/9024_2.png) [@senorsmile](https://forum.ansible.com/u/senorsmile)\
**Post date:** [February 20, 2018, 6:39pm UTC](https://forum.ansible.com/t/callback-plugin-get-list-of-hosts-in-init/26775/3 "2018-02-20T18:39:51Z")

</div>

Ah, I was starting to trace through Ansible but hadn’t found yet where the CallBack is instantiated.

v2\_playbook\_on\_play\_start receives an arg called “play”. That gives the list of nodes as their passed into the command line; i.e. names of groups are not broken out. I’d prefer to have a list of computed hosts at some point before v2\_playbook\_on\_stats at the very end.

---

<div class="post-metadata">

**Author:** ![senorsmile](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/senorsmile/32/9024_2.png) [@senorsmile](https://forum.ansible.com/u/senorsmile)\
**Post date:** [February 24, 2018, 5:49am UTC](https://forum.ansible.com/t/callback-plugin-get-list-of-hosts-in-init/26775/4 "2018-02-24T05:49:00Z")

</div>

this actually looks like what I’m looking for:

[https://groups.google.com/d/msg/ansible-devel/DQiGednLgU0/JIvQ2Z-zFQAJ](https://groups.google.com/d/msg/ansible-devel/DQiGednLgU0/JIvQ2Z-zFQAJ)

specifically the  
get\_variable\_manager()  
method.
