diff --git a/CHANGELOG.md b/CHANGELOG.md index 966912e2b6..deec3f5b7a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/lib/ansible/vars/manager.py b/lib/ansible/vars/manager.py index 6cac0cf2c1..2b401937bc 100644 --- a/lib/ansible/vars/manager.py +++ b/lib/ansible/vars/manager.py @@ -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)