1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Adjust relative include searches when roles are involved

Fixes #11895
This commit is contained in:
James Cammarata 2015-08-12 17:15:52 -04:00
parent d9833f227f
commit dd67b1e4d6

View file

@ -64,19 +64,24 @@ class IncludedFile:
original_task = iterator.get_original_task(res._host, res._task) original_task = iterator.get_original_task(res._host, res._task)
if original_task: if original_task:
if original_task._role: if original_task._task_include:
include_file = loader.path_dwim_relative(original_task._role._role_path, 'tasks', include_result['include'])
elif original_task._task_include:
# handle relative includes by walking up the list of parent include # handle relative includes by walking up the list of parent include
# tasks and checking the relative result to see if it exists # tasks and checking the relative result to see if it exists
parent_include = original_task._task_include parent_include = original_task._task_include
while parent_include is not None: while parent_include is not None:
parent_include_dir = os.path.dirname(parent_include.args.get('_raw_params')) parent_include_dir = os.path.dirname(parent_include.args.get('_raw_params'))
include_file = loader.path_dwim_relative(loader.get_basedir(), parent_include_dir, include_result['include']) if original_task._role:
new_basedir = os.path.join(original_task._role._role_path, 'tasks', parent_include_dir)
include_file = loader.path_dwim_relative(new_basedir, 'tasks', include_result['include'])
else:
include_file = loader.path_dwim_relative(loader.get_basedir(), parent_include_dir, include_result['include'])
if os.path.exists(include_file): if os.path.exists(include_file):
break break
else: else:
parent_include = parent_include._task_include parent_include = parent_include._task_include
elif original_task._role:
include_file = loader.path_dwim_relative(original_task._role._role_path, 'tasks', include_result['include'])
else: else:
include_file = loader.path_dwim(res._task.args.get('_raw_params')) include_file = loader.path_dwim(res._task.args.get('_raw_params'))
else: else: