summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Coca <brian.coca+git@gmail.com>2016-12-14 10:19:14 -0500
committerBrian Coca <brian.coca+git@gmail.com>2016-12-16 12:28:55 -0500
commitf90a6439c41c345f48ea4187278ba39dbdb182e3 (patch)
treebceeee85a3c6661a9e2897d2d139341aa5e60a29
parentd8449b3013c610d3ea998ed721a24dc27735f5fb (diff)
downloadansible-f90a6439c41c345f48ea4187278ba39dbdb182e3.tar.gz
correct template lookup path
now all paths get 'templates/' (cherry picked from commit ed933421fe63000b3ef9494184a5296ae620dd26)
-rw-r--r--lib/ansible/plugins/action/template.py23
1 files changed, 16 insertions, 7 deletions
diff --git a/lib/ansible/plugins/action/template.py b/lib/ansible/plugins/action/template.py
index 34f452f7a3..c7ca48e2a3 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