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
This commit is contained in:
Matt Martz 2020-10-29 14:15:18 -05:00 committed by GitHub
parent a51a6f4a25
commit e73a0b2460
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 19 additions and 2 deletions

View file

@ -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)

View file

@ -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)

View file

@ -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,
)

View file

@ -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

View file

@ -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