From e0b0e61b32904975d954fab35ca7ae02147fb6ea Mon Sep 17 00:00:00 2001 From: James Cammarata Date: Thu, 3 Aug 2017 15:01:36 -0500 Subject: [PATCH] Properly copy the role path when the IncludeRole object is copied This exposed some additional errors in logic in IncludeFile, which had to be fixed to deal with the fact that the role path (unlike paths from includes) are always absolute paths. Fixes #27345 --- lib/ansible/playbook/included_file.py | 8 ++++---- lib/ansible/playbook/role_include.py | 1 + 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/ansible/playbook/included_file.py b/lib/ansible/playbook/included_file.py index 025e4a4b2eb..07a0d235f84 100644 --- a/lib/ansible/playbook/included_file.py +++ b/lib/ansible/playbook/included_file.py @@ -103,13 +103,13 @@ class IncludedFile: parent_include = parent_include._parent continue if isinstance(parent_include, IncludeRole): - parent_include_dir = os.path.dirname(parent_include._role_path) + parent_include_dir = parent_include._role_path else: parent_include_dir = os.path.dirname(templar.template(parent_include.args.get('_raw_params'))) - if cumulative_path is None: - cumulative_path = parent_include_dir - elif not os.path.isabs(cumulative_path): + if cumulative_path is not None and not os.path.isabs(cumulative_path): cumulative_path = os.path.join(parent_include_dir, cumulative_path) + else: + cumulative_path = parent_include_dir include_target = templar.template(include_result['include']) if original_task._role: new_basedir = os.path.join(original_task._role._role_path, 'tasks', cumulative_path) diff --git a/lib/ansible/playbook/role_include.py b/lib/ansible/playbook/role_include.py index fbcc08c1736..89c0384511c 100644 --- a/lib/ansible/playbook/role_include.py +++ b/lib/ansible/playbook/role_include.py @@ -127,6 +127,7 @@ class IncludeRole(TaskInclude): new_me._from_files = self._from_files.copy() new_me._parent_role = self._parent_role new_me._role_name = self._role_name + new_me._role_path = self._role_path return new_me