|
|
@ -34,11 +34,12 @@ except ImportError:
|
|
|
|
|
|
|
|
|
|
|
|
class IncludedFile:
|
|
|
|
class IncludedFile:
|
|
|
|
|
|
|
|
|
|
|
|
def __init__(self, filename, args, task):
|
|
|
|
def __init__(self, filename, args, task, is_role=False):
|
|
|
|
self._filename = filename
|
|
|
|
self._filename = filename
|
|
|
|
self._args = args
|
|
|
|
self._args = args
|
|
|
|
self._task = task
|
|
|
|
self._task = task
|
|
|
|
self._hosts = []
|
|
|
|
self._hosts = []
|
|
|
|
|
|
|
|
self._is_role = is_role
|
|
|
|
|
|
|
|
|
|
|
|
def add_host(self, host):
|
|
|
|
def add_host(self, host):
|
|
|
|
if host not in self._hosts:
|
|
|
|
if host not in self._hosts:
|
|
|
@ -65,7 +66,7 @@ class IncludedFile:
|
|
|
|
original_host = res._host
|
|
|
|
original_host = res._host
|
|
|
|
original_task = res._task
|
|
|
|
original_task = res._task
|
|
|
|
|
|
|
|
|
|
|
|
if original_task.action in ('include', 'include_tasks'):
|
|
|
|
if original_task.action in ('include', 'include_tasks', 'include_role'):
|
|
|
|
if original_task.loop:
|
|
|
|
if original_task.loop:
|
|
|
|
if 'results' not in res._result:
|
|
|
|
if 'results' not in res._result:
|
|
|
|
continue
|
|
|
|
continue
|
|
|
@ -75,7 +76,7 @@ class IncludedFile:
|
|
|
|
|
|
|
|
|
|
|
|
for include_result in include_results:
|
|
|
|
for include_result in include_results:
|
|
|
|
# if the task result was skipped or failed, continue
|
|
|
|
# if the task result was skipped or failed, continue
|
|
|
|
if 'skipped' in include_result and include_result['skipped'] or 'failed' in include_result:
|
|
|
|
if 'skipped' in include_result and include_result['skipped'] or 'failed' in include_result and include_result['failed']:
|
|
|
|
continue
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
|
|
task_vars = variable_manager.get_vars(play=iterator._play, host=original_host, task=original_task)
|
|
|
|
task_vars = variable_manager.get_vars(play=iterator._play, host=original_host, task=original_task)
|
|
|
@ -88,49 +89,52 @@ class IncludedFile:
|
|
|
|
if loop_var in include_result:
|
|
|
|
if loop_var in include_result:
|
|
|
|
task_vars[loop_var] = include_variables[loop_var] = include_result[loop_var]
|
|
|
|
task_vars[loop_var] = include_variables[loop_var] = include_result[loop_var]
|
|
|
|
|
|
|
|
|
|
|
|
include_file = None
|
|
|
|
if original_task.action in ('include', 'include_tasks'):
|
|
|
|
if original_task:
|
|
|
|
include_file = None
|
|
|
|
if original_task.static:
|
|
|
|
if original_task:
|
|
|
|
continue
|
|
|
|
if original_task.static:
|
|
|
|
|
|
|
|
continue
|
|
|
|
if original_task._parent:
|
|
|
|
|
|
|
|
# handle relative includes by walking up the list of parent include
|
|
|
|
if original_task._parent:
|
|
|
|
# tasks and checking the relative result to see if it exists
|
|
|
|
# handle relative includes by walking up the list of parent include
|
|
|
|
parent_include = original_task._parent
|
|
|
|
# tasks and checking the relative result to see if it exists
|
|
|
|
cumulative_path = None
|
|
|
|
parent_include = original_task._parent
|
|
|
|
while parent_include is not None:
|
|
|
|
cumulative_path = None
|
|
|
|
if not isinstance(parent_include, TaskInclude):
|
|
|
|
while parent_include is not None:
|
|
|
|
parent_include = parent_include._parent
|
|
|
|
if not isinstance(parent_include, TaskInclude):
|
|
|
|
continue
|
|
|
|
parent_include = parent_include._parent
|
|
|
|
if isinstance(parent_include, IncludeRole):
|
|
|
|
continue
|
|
|
|
parent_include_dir = parent_include._role_path
|
|
|
|
if isinstance(parent_include, IncludeRole):
|
|
|
|
else:
|
|
|
|
parent_include_dir = parent_include._role_path
|
|
|
|
parent_include_dir = os.path.dirname(templar.template(parent_include.args.get('_raw_params')))
|
|
|
|
else:
|
|
|
|
if cumulative_path is not None and not os.path.isabs(cumulative_path):
|
|
|
|
parent_include_dir = os.path.dirname(templar.template(parent_include.args.get('_raw_params')))
|
|
|
|
cumulative_path = os.path.join(parent_include_dir, cumulative_path)
|
|
|
|
if cumulative_path is not None and not os.path.isabs(cumulative_path):
|
|
|
|
else:
|
|
|
|
cumulative_path = os.path.join(parent_include_dir, cumulative_path)
|
|
|
|
cumulative_path = parent_include_dir
|
|
|
|
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)
|
|
|
|
|
|
|
|
include_file = loader.path_dwim_relative(new_basedir, 'tasks', include_target)
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
include_file = loader.path_dwim_relative(loader.get_basedir(), cumulative_path, include_target)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if os.path.exists(include_file):
|
|
|
|
|
|
|
|
break
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
parent_include = parent_include._parent
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if include_file is None:
|
|
|
|
|
|
|
|
if original_task._role:
|
|
|
|
include_target = templar.template(include_result['include'])
|
|
|
|
include_target = templar.template(include_result['include'])
|
|
|
|
if original_task._role:
|
|
|
|
include_file = loader.path_dwim_relative(original_task._role._role_path, 'tasks', include_target)
|
|
|
|
new_basedir = os.path.join(original_task._role._role_path, 'tasks', cumulative_path)
|
|
|
|
else:
|
|
|
|
include_file = loader.path_dwim_relative(new_basedir, 'tasks', include_target)
|
|
|
|
include_file = loader.path_dwim(include_result['include'])
|
|
|
|
else:
|
|
|
|
|
|
|
|
include_file = loader.path_dwim_relative(loader.get_basedir(), cumulative_path, include_target)
|
|
|
|
include_file = templar.template(include_file)
|
|
|
|
|
|
|
|
inc_file = IncludedFile(include_file, include_variables, original_task)
|
|
|
|
if os.path.exists(include_file):
|
|
|
|
else:
|
|
|
|
break
|
|
|
|
inc_file = IncludedFile("role", include_variables, original_task, is_role=True)
|
|
|
|
else:
|
|
|
|
|
|
|
|
parent_include = parent_include._parent
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if include_file is None:
|
|
|
|
|
|
|
|
if original_task._role:
|
|
|
|
|
|
|
|
include_target = templar.template(include_result['include'])
|
|
|
|
|
|
|
|
include_file = loader.path_dwim_relative(original_task._role._role_path, 'tasks', include_target)
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
include_file = loader.path_dwim(include_result['include'])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
include_file = templar.template(include_file)
|
|
|
|
|
|
|
|
inc_file = IncludedFile(include_file, include_variables, original_task)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
pos = included_files.index(inc_file)
|
|
|
|
pos = included_files.index(inc_file)
|
|
|
|