Explicitly get the include task, and not assume it is the parent (#72378)

* Explicitly get the include task, and not assume it is the parent. Fixes #6571
pull/72408/head
Matt Martz 4 years ago committed by GitHub
parent a51a6f4a25
commit e73a0b2460
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,3 @@
bugfixes:
- Includes - Explicitly get the include task, and not assume it is the parent
(https://github.com/ansible/ansible/issues/65710)

@ -259,7 +259,7 @@ class StrategyModule(StrategyBase):
continue
for new_block in new_blocks:
task_vars = self._variable_manager.get_vars(play=iterator._play, task=new_block._parent,
task_vars = self._variable_manager.get_vars(play=iterator._play, task=new_block.get_first_parent_include(),
_hosts=self._hosts_cache,
_hosts_all=self._hosts_cache_all)
final_block = new_block.filter_tagged_tasks(task_vars)

@ -366,7 +366,7 @@ class StrategyModule(StrategyBase):
for new_block in new_blocks:
task_vars = self._variable_manager.get_vars(
play=iterator._play,
task=new_block._parent,
task=new_block.get_first_parent_include(),
_hosts=self._hosts_cache,
_hosts_all=self._hosts_cache_all,
)

@ -0,0 +1,11 @@
- hosts: localhost
gather_facts: false
tasks:
- include_tasks:
file: include_tasks.yml
apply:
tags: always
- assert:
that:
- include_tasks_result is defined

@ -81,6 +81,9 @@ if [[ -z "$OUT" ]]; then
exit 1
fi
ANSIBLE_STRATEGY='linear' ANSIBLE_PLAYBOOK_VARS_ROOT=all ansible-playbook apply/include_apply_65710.yml -i inventory "$@"
ANSIBLE_STRATEGY='free' ANSIBLE_PLAYBOOK_VARS_ROOT=all ansible-playbook apply/include_apply_65710.yml -i inventory "$@"
# Test that duplicate items in loop are not deduped
ANSIBLE_STRATEGY='linear' ansible-playbook tasks/test_include_dupe_loop.yml -i inventory "$@" | tee test_include_dupe_loop.out
test "$(grep -c '"item=foo"' test_include_dupe_loop.out)" = 3

Loading…
Cancel
Save