From 640d057f3fdbce14f3d32354465933510732f899 Mon Sep 17 00:00:00 2001 From: James Cammarata Date: Thu, 20 Jul 2017 12:32:06 -0500 Subject: [PATCH] Don't use _raw_params for IncludeRole objects (#26601) IncludeRole objects don't use _raw_params for the name/etc. of roles like regular incudes, but the code for finding relative includes assumed that all includes had a _raw_params field. This fixes that by correctly checking the parent object type and using the appropriate field. Fixes #26525 --- lib/ansible/playbook/included_file.py | 6 +++++- lib/ansible/playbook/role_include.py | 4 ++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/ansible/playbook/included_file.py b/lib/ansible/playbook/included_file.py index b9f7b3a25d4..025e4a4b2eb 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 a2309b914fc..fbcc08c1736 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: