mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-06 13:22:48 +00:00
Fix searchpath in the template lookup (#50488)
This commit is contained in:
2
changelogs/fragments/template-lookup-searchpath-fix.yaml
Normal file
2
changelogs/fragments/template-lookup-searchpath-fix.yaml
Normal file
@@ -0,0 +1,2 @@
|
||||
bugfixes:
|
||||
- Fix searchpath in the template lookup to work the same way as in the template module.
|
||||
@@ -77,7 +77,7 @@ class LookupModule(LookupBase):
|
||||
template_data = to_text(f.read(), errors='surrogate_or_strict')
|
||||
|
||||
# set jinja2 internal search path for includes
|
||||
searchpath = variables.get('ansible_search_path')
|
||||
searchpath = variables.get('ansible_search_path', [])
|
||||
if searchpath:
|
||||
# our search paths aren't actually the proper ones for jinja includes.
|
||||
# We want to search into the 'templates' subdir of each search path in
|
||||
@@ -87,8 +87,8 @@ class LookupModule(LookupBase):
|
||||
newsearchpath.append(os.path.join(p, 'templates'))
|
||||
newsearchpath.append(p)
|
||||
searchpath = newsearchpath
|
||||
else:
|
||||
searchpath = [self._loader._basedir, os.path.dirname(lookupfile)]
|
||||
searchpath.insert(0, os.path.dirname(lookupfile))
|
||||
|
||||
self._templar.environment.loader.searchpath = searchpath
|
||||
if variable_start_string is not None:
|
||||
self._templar.environment.variable_start_string = variable_start_string
|
||||
|
||||
Reference in New Issue
Block a user