# callback module and host variables

**URL:** <https://forum.ansible.com/t/callback-module-and-host-variables/18215>\
**Category:** Ansible Project\
**Created:** [May 12, 2015, 7:27pm UTC](https://forum.ansible.com/t/callback-module-and-host-variables/18215 "2015-05-12T19:27:50Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chris\_Fidao](https://avatars.discourse-cdn.com/v4/letter/c/2acd7d/32.png) [@Chris\_Fidao](https://forum.ansible.com/u/Chris_Fidao)\
**Post date:** [May 12, 2015, 7:27pm UTC](https://forum.ansible.com/t/callback-module-and-host-variables/18215/1 "2015-05-12T19:27:50Z")

</div>

I haven’t been able to find information on this - I’ve created a callback module to create log output that I can save to a database in order to display the result of a run in an administrative control panel.

There are some meta data I’d like to put into the database for this logging, some of which given to Ansible by way of host variables

I’m wondering if I can access those host variables from within the callback module used - I don’t see anything obvious when scanning the code base.

Thanks!

---

<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:** [May 12, 2015, 7:33pm UTC](https://forum.ansible.com/t/callback-module-and-host-variables/18215/2 "2015-05-12T19:33:12Z")

</div>

host vars are not passed to callbacks.

---

<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:** [May 12, 2015, 7:38pm UTC](https://forum.ansible.com/t/callback-module-and-host-variables/18215/3 "2015-05-12T19:38:25Z")

</div>

You can access hostvars in a callback, those specified by inventory are “easiest” such as:

hosts = self.playbook.inventory.get\_hosts()  
host\_vars = self.playbook.inventory.get\_variables(hosts[0].name,  
self.playbook.vault\_password)

You have access to self.task, self.play and self.playbook. All of those objects have a number of accessible methods and attributes that you can generally use to find the info you need.

Be aware though, that the v2 code branch will likely cause some backwards incompatibilities in accessing those attributes in the future.
