for g in self.inventory.get_groups():
vars = self.inventory.get_group_vars(g)
print(“… vars for group %s” % g.name)
for v in vars:
print(“%s = %s” % (v, vars.get(v)))
…
`
Error:
`
[WARNING]: Error when using <bound method CallbackModule.v2_playbook_on_play_start of <…CallbackModule object at 0x7fbf9c8c8c50>>: ‘Play’ object
has no attribute ‘playbook’
`
How should i access group/host variables from callback module in ansible-2.0?
self._display.vvvv(‘… group vars’)
for g in inv.get_groups():
self._display.vvvv(‘… group=’ + str(g))
self._display.vvvv(‘… value=’ + str(inv.get_group_variables(g)))
g_vars = inv.get_group_variables(g)
get vars if not defined already (hopping groups are sorted)
if self.myvar is None: self.myvar = g_vars.get(“myvar”, None)
host vars
self._display.vvvv(‘… host vars’)
for h in inv.get_hosts():
self._display.vvvv(‘… host =’ + str(h))
self._display.vvvv(‘… value=’ + str(inv.get_host_vars(h)))
h_vars = inv.get_host_vars(h)
if self.myvar is None: self.myvar = h_vars.get(“myvar”, None)