diff options
author | kiorky <kiorky@cryptelium.net> | 2018-01-31 14:35:06 +0100 |
---|---|---|
committer | James Cammarata <jimi@sngx.net> | 2018-01-31 07:35:06 -0600 |
commit | 9001a8794f19053f52a807cb59ced87357873e9e (patch) | |
tree | eecbc517f7a8cbe7a33811b6e92c211973201b71 /lib/ansible/playbook/included_file.py | |
parent | 984edacd2adaf4c3dc53da1821011e8726815ee7 (diff) | |
download | ansible-9001a8794f19053f52a807cb59ced87357873e9e.tar.gz |
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
Diffstat (limited to 'lib/ansible/playbook/included_file.py')
-rw-r--r-- | lib/ansible/playbook/included_file.py | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/lib/ansible/playbook/included_file.py b/lib/ansible/playbook/included_file.py index 6bcd631ce2..f565a4aa0c 100644 --- a/lib/ansible/playbook/included_file.py +++ b/lib/ansible/playbook/included_file.py @@ -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) |