From ed933421fe63000b3ef9494184a5296ae620dd26 Mon Sep 17 00:00:00 2001 From: Brian Coca Date: Wed, 14 Dec 2016 10:19:14 -0500 Subject: [PATCH] correct template lookup path now all paths get 'templates/' --- lib/ansible/plugins/action/template.py | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/lib/ansible/plugins/action/template.py b/lib/ansible/plugins/action/template.py index 43dc6922ed..7b1d26893d 100644 --- a/lib/ansible/plugins/action/template.py +++ b/lib/ansible/plugins/action/template.py @@ -115,13 +115,22 @@ class ActionModule(ActionBase): time.localtime(os.path.getmtime(b_source)) ) - # Create a new searchpath list to assign to the templar environment's file - # loader, so that it knows about the other paths to find template files - searchpath = [self._loader._basedir, os.path.dirname(source)] - if self._task._role is not None: - if C.DEFAULT_ROLES_PATH: - searchpath[:0] = C.DEFAULT_ROLES_PATH - searchpath.insert(1, self._task._role._role_path) + + searchpath = [] + # set jinja2 internal search path for includes + if 'ansible_search_path' in task_vars: + searchpath = task_vars['ansible_search_path'] + # our search paths aren't actually the proper ones for jinja includes. + + searchpath.extend([self._loader._basedir, os.path.dirname(source)]) + + # We want to search into the 'templates' subdir of each search path in + # addition to our original search paths. + newsearchpath = [] + for p in searchpath: + newsearchpath.append(os.path.join(p, 'templates')) + newsearchpath.append(p) + searchpath = newsearchpath self._templar.environment.loader.searchpath = searchpath