Is there any equivalent way of doing the above in V2?
I’ve been playing with the context_demo plugin and can see it gets passed an
ansible.playbook.Playbook object
when I look at that it has a get_plays method, but that doesn’t seem to return anything. Looking through the Playbook code, one of the things it does is load the plugins, so its like I’m trying to get at inventory (via the playbook) before it has been initialised.
Is there another way to get at host vars? Or is there a different callback I can use, after the inventory has been loaded?
so, the following is a bit messy but hopefully will help anyone else trying to do something similar…
in my def v2_playbook_on_play_start(self, *args, **kwargs)
args[0] turned out to be Playbook object, which you can call get_variable_manager() on
you can get inventory from variable manager via
_inventory
then you can get hosts by calling
get_hosts() on the inventory
then you can iterate through the hosts
and call get_vars()
or get_group_vars()
both of which are dicts, so you can lookup whatever values you are interested in.