callback module and host variables

58 views
Skip to first unread message

Chris Fidao

unread,
May 12, 2015, 3:32:33 PM5/12/15
to ansible...@googlegroups.com
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!

Brian Coca

unread,
May 12, 2015, 3:33:15 PM5/12/15
to ansible...@googlegroups.com
host vars are not passed to callbacks.





--
Brian Coca

Matt Martz

unread,
May 12, 2015, 3:39:09 PM5/12/15
to ansible...@googlegroups.com
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.

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/8ae57895-39da-4f38-9c33-6e93c2ad9abd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Matt Martz
@sivel
sivel.net
Reply all
Reply to author
Forward
0 new messages