FIX: multiple nested tasks include levels (#35165)
* Test for include_tasks & include_role bug Related to ansible/ansible:#21890 * Fix nested include_tasks called from role This fixes the path of included files when you want to call include_task inside a role's task file and this role is itself called from multiple level of playbook include_tasks Related to ansible/ansible:#21890 This fixes ansible/ansible:#35109
This commit is contained in:
parent
984edacd2a
commit
9001a8794f
28 changed files with 77 additions and 1 deletions
|
@ -109,7 +109,16 @@ class IncludedFile:
|
|||
include_target = templar.template(include_result['include'])
|
||||
if original_task._role:
|
||||
new_basedir = os.path.join(original_task._role._role_path, 'tasks', cumulative_path)
|
||||
include_file = loader.path_dwim_relative(new_basedir, 'tasks', include_target)
|
||||
candidates = [loader.path_dwim_relative(original_task._role._role_path, 'tasks', include_target),
|
||||
loader.path_dwim_relative(new_basedir, 'tasks', include_target)]
|
||||
for include_file in candidates:
|
||||
try:
|
||||
# may throw OSError
|
||||
os.stat(include_file)
|
||||
# or select the task file if it exists
|
||||
break
|
||||
except OSError:
|
||||
pass
|
||||
else:
|
||||
include_file = loader.path_dwim_relative(loader.get_basedir(), cumulative_path, include_target)
|
||||
|
||||
|
|
6
test/integration/targets/include_import/nested.yml
Normal file
6
test/integration/targets/include_import/nested.yml
Normal file
|
@ -0,0 +1,6 @@
|
|||
- name: >-
|
||||
verify that multiple level of nested statements and
|
||||
include+meta doesnt mess included files mecanisms
|
||||
hosts: testhost
|
||||
tasks:
|
||||
- include_tasks: ./tasks/nested/nested.yml
|
|
@ -0,0 +1,2 @@
|
|||
---
|
||||
- include_role: {name: nested_include_task}
|
|
@ -0,0 +1,3 @@
|
|||
---
|
||||
testnesteddep2_defvar1: foobar
|
||||
testnesteddep2_varvar1: foobar
|
|
@ -0,0 +1,2 @@
|
|||
dependencies:
|
||||
- role: nested/nested/nested_dep_role2a
|
|
@ -0,0 +1,2 @@
|
|||
---
|
||||
- include_tasks: ./rund.yml
|
|
@ -0,0 +1,2 @@
|
|||
---
|
||||
- shell: echo from deprole2a
|
|
@ -0,0 +1,2 @@
|
|||
---
|
||||
testnesteddep2_varvar1: muche
|
|
@ -0,0 +1,3 @@
|
|||
---
|
||||
testnesteddep2_defvar1: foobar
|
||||
testnesteddep2_varvar1: foobar
|
|
@ -0,0 +1,2 @@
|
|||
dependencies:
|
||||
- role: nested/nested/nested_dep_role2b
|
|
@ -0,0 +1,2 @@
|
|||
---
|
||||
- include_tasks: ./rune.yml
|
|
@ -0,0 +1,2 @@
|
|||
---
|
||||
- shell: echo from deprole2
|
|
@ -0,0 +1,2 @@
|
|||
---
|
||||
testnesteddep2_varvar1: muche
|
|
@ -0,0 +1,3 @@
|
|||
---
|
||||
testnesteddep2_defvar1: foobar
|
||||
testnesteddep2_varvar1: foobar
|
|
@ -0,0 +1 @@
|
|||
dependencies: []
|
|
@ -0,0 +1,2 @@
|
|||
---
|
||||
- include_tasks: ./runf.yml
|
|
@ -0,0 +1,2 @@
|
|||
---
|
||||
- shell: echo from deprole2b
|
|
@ -0,0 +1,2 @@
|
|||
---
|
||||
testnesteddep2_varvar1: muche
|
|
@ -0,0 +1,3 @@
|
|||
---
|
||||
testnesteddep_defvar1: foobar
|
||||
testnesteddep_varvar1: foobar
|
|
@ -0,0 +1,2 @@
|
|||
---
|
||||
dependencies: []
|
|
@ -0,0 +1,2 @@
|
|||
---
|
||||
- include_tasks: ./runc.yml
|
|
@ -0,0 +1,4 @@
|
|||
---
|
||||
- debug:
|
||||
msg: from test_nested_dep_role
|
||||
- include_role: {name: nested/nested/nested_dep_role2}
|
|
@ -0,0 +1,2 @@
|
|||
---
|
||||
testnesteddep_varvar1: muche
|
|
@ -0,0 +1,2 @@
|
|||
dependencies:
|
||||
- role: nested/nested_dep_role
|
|
@ -0,0 +1,2 @@
|
|||
---
|
||||
- include_tasks: ./runa.yml
|
|
@ -0,0 +1,3 @@
|
|||
---
|
||||
- debug:
|
||||
msg: from nested_include_task
|
|
@ -36,3 +36,8 @@ ANSIBLE_STRATEGY='free' ansible-playbook role/test_include_role.yml -i ../../inv
|
|||
## Recursion
|
||||
# https://github.com/ansible/ansible/issues/23609
|
||||
ANSIBLE_STRATEGY='linear' ansible-playbook test_recursion.yml -i ../../inventory "$@" --skip-tags never
|
||||
|
||||
## Nested tasks
|
||||
# https://github.com/ansible/ansible/issues/34782
|
||||
ANSIBLE_STRATEGY='linear' ansible-playbook nested.yml -i ../../inventory "$@" --skip-tags never
|
||||
ANSIBLE_STRATEGY='free' ansible-playbook nested.yml -i ../../inventory "$@" --skip-tags never
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
---
|
||||
- include_tasks: ../../nestedtasks/nested/nested.yml
|
Loading…
Reference in a new issue