fix item var in delegation (#32986)

* fix item var in delegation

* fixed task ref

* in case no loop

(cherry picked from commit e19c994f57)
This commit is contained in:
Brian Coca 2017-11-20 09:29:55 -05:00 committed by Brian Coca
parent e208a522fe
commit bc0a0fb99c
2 changed files with 4 additions and 1 deletions

View file

@ -182,6 +182,8 @@ Ansible Changes By Release
https://github.com/ansible/ansible/pull/32866
* restore host/group_vars merge order
https://github.com/ansible/ansible/pull/32963
* use correct loop var when delegating
https://github.com/ansible/ansible/pull/32986
<a id="2.4.1"></a>

View file

@ -534,10 +534,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)