From c96c8532c895b6551b7098307c15b7df0c4df7d0 Mon Sep 17 00:00:00 2001 From: Virgil Dupras Date: Thu, 24 Nov 2016 13:17:05 -0500 Subject: [PATCH] Fix regression in jinja2 include search path Since commit 3c39bb5, the 'ansible_search_path' variable is used to set jinja2's search path for {% include %} directives. However, this path is the the proper one because our templates live in 'templates' subdirs in our search path. This is a regression because previously, our include search path would include the dirname of the currently interpreted file, which worked most of the time. fixes #18526 --- lib/ansible/plugins/lookup/template.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/ansible/plugins/lookup/template.py b/lib/ansible/plugins/lookup/template.py index 4ab0ad1ed02..3bddfa3a03f 100644 --- a/lib/ansible/plugins/lookup/template.py +++ b/lib/ansible/plugins/lookup/template.py @@ -49,6 +49,9 @@ class LookupModule(LookupBase): # set jinja2 internal search path for includes if 'ansible_search_path' in variables: searchpath = variables['ansible_search_path'] + # our search paths aren't actually the proper ones for jinja includes. + # We want to search into the 'templates' subdir of each search path. + searchpath = [os.path.join(p, 'templates') for p in searchpath] else: searchpath = [self._loader._basedir, os.path.dirname(lookupfile)] self._templar.environment.loader.searchpath = searchpath