callback module and host variables

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!

host vars are not passed to callbacks.

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.