-
Notifications
You must be signed in to change notification settings - Fork 23.8k
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
Handlers delegated to a list of items fails when "with_items" is provided with a fact #15103
Comments
Made some edits for clarity. |
This happens when trying to run
|
This seems to fix it: diff --git a/lib/ansible/vars/__init__.py b/lib/ansible/vars/__init__.py
index 26d03f0..fec857c 100644
--- a/lib/ansible/vars/__init__.py
+++ b/lib/ansible/vars/__init__.py
@@ -366,10 +366,11 @@ class VariableManager:
if host:
variables['group_names'] = sorted([group.name for group in host.get_groups() if group.name != 'all'])
- if self._inventory is not None:
- variables['groups'] = dict()
- for (group_name, group) in iteritems(self._inventory.groups):
- variables['groups'][group_name] = [h.name for h in group.get_hosts()]
+ if self._inventory is not None:
+ variables['groups'] = dict()
+ for (group_name, group) in iteritems(self._inventory.groups):
+ variables['groups'][group_name] = [h.name for h in group.get_hosts()]
+
if play:
variables['role_names'] = [r._role_name for r in play.roles] I'm not sure why |
I confirm the bug, I've the same issue in my playbook with Ansible 2.1.0. @ktosiek I vote to make a pull request for that. |
I am having the same issue
This does not help either in accounts.yml:
If I run a debug by adding tasks into accounts.yml it does print the group:
|
Note that the workaround proposed in #12170 does not seem to work, blocking us from migrating to Ansible 2.x. |
After some tests, it seems it only happens for me when a given host is skipped. https://gist.github.com/turb/278dc6378e9045da1fe5ad278c7bed01 |
So i can reproduce this on 2.0.1 but it seems to have been working since 2.0.2 (I'm not going to track down exact commit that fixed it). I also checked 2.1.3 and 2.2, so I'm going to close this as 'fixed'. |
@turb your issue is unrelated, |
@bcoca it did work in 1.9 By all means the |
@turb it did AND did not 'work' in 1.9, 1.9 was just ignoring the undefined error. In 2.0 we 'fixed that' and showed the error, but since it broke many people's playbook we changed it from error to a deprecation message. As is our normal procedure with deprecations, we removed it and it is an error again in 2.2. |
@bcoca ok, will proceed by the doc, thanks. |
Issue Type:
Ansible Version:
Ansible Configuration:
N/A
Environment:
N/A
Summary:
A common workflow is to delegate a task to a list of hosts, like so:
In 1.x, this works in both regular tasks and in handlers. In 2.x, tasks work fine but handlers fail with (in this example) "ERROR! groups is undefined". This seems to be the case if any "fact" is used in with_items. It does not happen when a variable that is not a fact is used. It also does not fail if the fact is set in
delegate_to
or if the fact is set inwith_items
without being delegated - failure occurs only when the fact is supplied to awith_items
in the same action as adelegate_to
. It does not matter whether{{ item }}
is referenced bydelegate_to
or some other part of the action.Steps To Reproduce:
delegate_to
and awith_items
, and supplywith_items
with any fact.This playbook will demonstrate the issue - please see the comments for details.
Expected Results:
I would expect to see the handler run on each of the delegated hosts.
Actual Results:
The play fails when the handler is sourced (immediately if it's a regular playbook, or when the role is called if the handler is in a role) with the error: "ERROR! [some_fact] is undefined" (with whatever fact was used in with_items):
The text was updated successfully, but these errors were encountered: