From e19c994f5798b8bdcc7c3cfd89d5f7e575bacdeb Mon Sep 17 00:00:00 2001 From: Brian Coca Date: Mon, 20 Nov 2017 09:29:55 -0500 Subject: [PATCH] fix item var in delegation (#32986) * fix item var in delegation * fixed task ref * in case no loop --- lib/ansible/vars/manager.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/ansible/vars/manager.py b/lib/ansible/vars/manager.py index b5f9b8d1ebe..8d3110b7057 100644 --- a/lib/ansible/vars/manager.py +++ b/lib/ansible/vars/manager.py @@ -43,7 +43,7 @@ from ansible.template import Templar from ansible.utils.listify import listify_lookup_plugin_terms from ansible.utils.vars import combine_vars from ansible.utils.unsafe_proxy import wrap_var -from ansible.vars.clean import namespace_facts, clean_facts +from ansible.vars.clean import namespace_facts try: from __main__ import display @@ -518,10 +518,11 @@ class VariableManager: items = [None] delegated_host_vars = dict() + item_var = getattr(task.loop_control, 'loop_var', 'item') for item in items: # update the variables with the item value for templating, in case we need it if item is not None: - vars_copy['item'] = item + vars_copy[item_var] = item templar.set_available_variables(vars_copy) delegated_host_name = templar.template(task.delegate_to, fail_on_undefined=False)