diff --git a/lib/ansible/playbook/included_file.py b/lib/ansible/playbook/included_file.py index b9f7b3a25d..025e4a4b2e 100644 --- a/lib/ansible/playbook/included_file.py +++ b/lib/ansible/playbook/included_file.py @@ -22,6 +22,7 @@ __metaclass__ = type import os from ansible.playbook.task_include import TaskInclude +from ansible.playbook.role_include import IncludeRole from ansible.template import Templar try: @@ -101,7 +102,10 @@ class IncludedFile: if not isinstance(parent_include, TaskInclude): parent_include = parent_include._parent continue - parent_include_dir = os.path.dirname(templar.template(parent_include.args.get('_raw_params'))) + if isinstance(parent_include, IncludeRole): + parent_include_dir = os.path.dirname(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): diff --git a/lib/ansible/playbook/role_include.py b/lib/ansible/playbook/role_include.py index a2309b914f..fbcc08c173 100644 --- a/lib/ansible/playbook/role_include.py +++ b/lib/ansible/playbook/role_include.py @@ -58,6 +58,7 @@ class IncludeRole(TaskInclude): self._from_files = {} self._parent_role = role self._role_name = None + self._role_path = None def get_block_list(self, play=None, variable_manager=None, loader=None): @@ -74,6 +75,9 @@ class IncludeRole(TaskInclude): actual_role = Role.load(ri, myplay, parent_role=self._parent_role, from_files=self._from_files) actual_role._metadata.allow_duplicates = self.allow_duplicates + # save this for later use + self._role_path = actual_role._role_path + # compile role with parent roles as dependencies to ensure they inherit # variables if not self._parent_role: