Fix searchpath in the template lookup (#50488)
This commit is contained in:
parent
98b0ef370d
commit
82c95e07b5
2 changed files with 5 additions and 3 deletions
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')
|
template_data = to_text(f.read(), errors='surrogate_or_strict')
|
||||||
|
|
||||||
# set jinja2 internal search path for includes
|
# set jinja2 internal search path for includes
|
||||||
searchpath = variables.get('ansible_search_path')
|
searchpath = variables.get('ansible_search_path', [])
|
||||||
if searchpath:
|
if searchpath:
|
||||||
# our search paths aren't actually the proper ones for jinja includes.
|
# 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
|
# 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(os.path.join(p, 'templates'))
|
||||||
newsearchpath.append(p)
|
newsearchpath.append(p)
|
||||||
searchpath = newsearchpath
|
searchpath = newsearchpath
|
||||||
else:
|
searchpath.insert(0, os.path.dirname(lookupfile))
|
||||||
searchpath = [self._loader._basedir, os.path.dirname(lookupfile)]
|
|
||||||
self._templar.environment.loader.searchpath = searchpath
|
self._templar.environment.loader.searchpath = searchpath
|
||||||
if variable_start_string is not None:
|
if variable_start_string is not None:
|
||||||
self._templar.environment.variable_start_string = variable_start_string
|
self._templar.environment.variable_start_string = variable_start_string
|
||||||
|
|
Loading…
Reference in a new issue