From 6c036c363337553cfaf3d3b6aea478579d00d54c Mon Sep 17 00:00:00 2001 From: James Cammarata Date: Thu, 13 Aug 2015 13:01:31 -0400 Subject: [PATCH] Template parent include file paths Fixes #11955 --- lib/ansible/playbook/included_file.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/lib/ansible/playbook/included_file.py b/lib/ansible/playbook/included_file.py index e4a1b85aa0c..d8bc497dcf1 100644 --- a/lib/ansible/playbook/included_file.py +++ b/lib/ansible/playbook/included_file.py @@ -63,13 +63,21 @@ class IncludedFile: continue original_task = iterator.get_original_task(res._host, res._task) + + task_vars = variable_manager.get_vars(loader=loader, play=iterator._play, host=res._host, task=original_task) + templar = Templar(loader=loader, variables=task_vars) + + include_variables = include_result.get('include_variables', dict()) + if 'item' in include_result: + task_vars['item'] = include_variables['item'] = include_result['item'] + if original_task: if original_task._task_include: # handle relative includes by walking up the list of parent include # tasks and checking the relative result to see if it exists parent_include = original_task._task_include while parent_include is not None: - parent_include_dir = os.path.dirname(parent_include.args.get('_raw_params')) + parent_include_dir = templar.template(os.path.dirname(parent_include.args.get('_raw_params'))) 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']) @@ -87,15 +95,6 @@ class IncludedFile: else: include_file = loader.path_dwim(res._task.args.get('_raw_params')) - task_vars = variable_manager.get_vars(loader=loader, play=iterator._play, host=res._host, task=original_task) - #task_vars = tqm.add_tqm_variables(task_vars, play=iterator._play) - - include_variables = include_result.get('include_variables', dict()) - if 'item' in include_result: - include_variables['item'] = include_result['item'] - task_vars['item'] = include_result['item'] - - templar = Templar(loader=loader, variables=task_vars) include_file = templar.template(include_file) inc_file = IncludedFile(include_file, include_variables, original_task)