Fix handling of ansible_loop_var and ansible_index_var inside ansible.builtin.include_tasks (#82789)

* added integration test for issue 82655 regarding ansible_loop_var and ansible_index_var inside included yml

* ensure correct handling of ansible_loop_var and ansible_index_var inside ansible builtin include_tasks Co-authored-by: Matt <matt@sivel.net>

* added changelog

* fixed new line issue
pull/82725/head
Thomas W 2 years ago committed by GitHub
parent 2cf52daa03
commit 6db7a3bd64
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,2 @@
bugfixes:
- include_tasks - include `ansible_loop_var` and `ansible_index_var` in a loop (https://github.com/ansible/ansible/issues/82655).

@ -95,8 +95,10 @@ class IncludedFile:
index_var = include_result.get('ansible_index_var')
if loop_var in include_result:
task_vars[loop_var] = special_vars[loop_var] = include_result[loop_var]
task_vars['ansible_loop_var'] = special_vars['ansible_loop_var'] = loop_var
if index_var and index_var in include_result:
task_vars[index_var] = special_vars[index_var] = include_result[index_var]
task_vars['ansible_index_var'] = special_vars['ansible_index_var'] = index_var
if '_ansible_item_label' in include_result:
task_vars['_ansible_item_label'] = special_vars['_ansible_item_label'] = include_result['_ansible_item_label']
if 'ansible_loop' in include_result:

@ -0,0 +1,5 @@
- name: Assert ansible_loop_var and ansible_index_var are defined with correct values
assert:
that:
- ansible_loop_var is defined and ansible_index_var is defined
- ansible_loop_var == "should_show_up_loop" and ansible_index_var == "should_show_up_index"

@ -42,3 +42,10 @@
- name: include_tasks + action
action: include_tasks tasks1.yml
- name: Test ansible_loop_var and ansible_index_var within included_tasks
include_tasks: task_ansible_loop_index_var.yml
loop: ['does not matter', 'dont care']
loop_control:
loop_var: should_show_up_loop
index_var: should_show_up_index

Loading…
Cancel
Save