-
Notifications
You must be signed in to change notification settings - Fork 23.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot access groups of a host from within a callback plugin #15538
Comments
Not sure if this is what you need, but fairly certain it will get get group vars from groups other than the 'all' group like this.
|
Thanks for this hint. This seems to do the trick as a workaround.
Outcome:
Still, I wonder why |
not a bug, this info is not supplied on purpose, callbacks are given a narrow access to data. The 'hack' above is not guaranteed to always work and is unsupported. |
Closing per above. If you have further questions please stop by IRC or the mailing list:
|
ISSUE TYPE
COMPONENT NAME
callback plugins
ANSIBLE VERSION
CONFIGURATION
OS / ENVIRONMENT
SUMMARY
In a callback plugin, in the method v2_runner_on_failed(self, result, ignore_errors=False) I want to retrieve the groups of a host but it always returns an empty list.
STEPS TO REPRODUCE
Please see https://github.com/rawbertp/ansible_callback_plugin_issue/blob/master/plugins/callback_plugins/dummy.py and code below.
The group var "foo" is set in group_vars/all (="all"), group_vars/prod (="prod") and group_vars/test (="test").
Now I run my playbook as follows:
Running it for "inventory/test" I'd expect the callback plugin to return "test" as a value for foo whereas for "inventory/prod" it should be prod. However, it always returns "all".
The line
self.play._variable_manager.get_vars(self.loader, play=self.play, task=result._task, host=result._host, use_cache=False)
only returns group vars set in "all".
The problem is that result._host.get_groups() always returns an empty [] list.
EXPECTED RESULTS
In my example (https://github.com/rawbertp/ansible_callback_plugin_issue/) I'd expect
result._host.get_groups()
to return [frontend, prod] or [frontend, test] depending on the inventory chosen and
self.play._variable_manager.get_vars(self.loader, play=self.play, task=result._task, host=result._host, use_cache=False)
to return the actually effective vars for the task.
inventory/prod -> foo == "prod"
inventory/test -> foo == "test"
ACTUAL RESULTS
result._host.get_groups()
always returns an empty [] list.self.play._variable_manager.get_vars(self.loader, play=self.play, task=result._task, host=result._host, use_cache=False)
only returns the "all" group vars.inventory/prod -> foo == "all"
inventory/test -> foo == "all"
The text was updated successfully, but these errors were encountered: