Skip to content

Commit

Permalink
Don't use _raw_params for IncludeRole objects (ansible#26601)
Browse files Browse the repository at this point in the history
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 ansible#26525
  • Loading branch information
jimi-c authored Jul 20, 2017
1 parent bf63301 commit 640d057
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/ansible/playbook/included_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import os

from ansible.playbook.task_include import TaskInclude
from ansible.playbook.role_include import IncludeRole
from ansible.template import Templar

try:
Expand Down Expand Up @@ -101,7 +102,10 @@ def get_original_host(host):
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):
Expand Down
4 changes: 4 additions & 0 deletions lib/ansible/playbook/role_include.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ def __init__(self, block=None, role=None, task_include=None):
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):

Expand All @@ -74,6 +75,9 @@ def get_block_list(self, play=None, variable_manager=None, loader=None):
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:
Expand Down

0 comments on commit 640d057

Please sign in to comment.