Browse code

fix item var in delegation (#32986)

* fix item var in delegation

* fixed task ref

* in case no loop

(cherry picked from commit e19c994f5798b8bdcc7c3cfd89d5f7e575bacdeb)

Brian Coca authored on 2017/11/20 23:29:55
Showing 2 changed files
... ...
@@ -182,6 +182,8 @@ Ansible Changes By Release
182 182
   https://github.com/ansible/ansible/pull/32866
183 183
 * restore host/group_vars merge order
184 184
   https://github.com/ansible/ansible/pull/32963
185
+* use correct loop var when delegating
186
+  https://github.com/ansible/ansible/pull/32986
185 187
 
186 188
 <a id="2.4.1"></a>
187 189
 
... ...
@@ -534,10 +534,11 @@ class VariableManager:
534 534
             items = [None]
535 535
 
536 536
         delegated_host_vars = dict()
537
+        item_var = getattr(task.loop_control, 'loop_var', 'item')
537 538
         for item in items:
538 539
             # update the variables with the item value for templating, in case we need it
539 540
             if item is not None:
540
-                vars_copy['item'] = item
541
+                vars_copy[item_var] = item
541 542
 
542 543
             templar.set_available_variables(vars_copy)
543 544
             delegated_host_name = templar.template(task.delegate_to, fail_on_undefined=False)