mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
parent
479c4a4be9
commit
dbd755e0f4
3 changed files with 13 additions and 1 deletions
|
@ -111,6 +111,11 @@ class ActionModule(ActionBase):
|
|||
time.localtime(os.path.getmtime(source))
|
||||
)
|
||||
|
||||
self._templar.environment.searchpath = [self._loader._basedir, os.path.dirname(source)]
|
||||
if self._task._role is not None:
|
||||
self._templar.environment.searchpath.insert(1, C.DEFAULT_ROLES_PATH)
|
||||
self._templar.environment.searchpath.insert(1, self._task._role._role_path)
|
||||
|
||||
old_vars = self._templar._available_variables
|
||||
self._templar.set_available_variables(temp_vars)
|
||||
resultant = self._templar.template(template_data, preserve_trailing_newlines=True, convert_data=False)
|
||||
|
|
|
@ -19,6 +19,7 @@ __metaclass__ = type
|
|||
|
||||
import os
|
||||
|
||||
from ansible import constants as C
|
||||
from ansible.errors import AnsibleError
|
||||
from ansible.plugins.lookup import LookupBase
|
||||
|
||||
|
@ -41,6 +42,12 @@ class LookupModule(LookupBase):
|
|||
if lookupfile and os.path.exists(lookupfile):
|
||||
with open(lookupfile, 'r') as f:
|
||||
template_data = f.read()
|
||||
|
||||
self._templar.environment.searchpath = [self._loader._basedir, os.path.dirname(lookupfile)]
|
||||
if 'role_path' in variables:
|
||||
self._templar.environment.searchpath.insert(1, C.DEFAULT_ROLES_PATH)
|
||||
self._templar.environment.searchpath.insert(1, variables['role_path'])
|
||||
|
||||
res = self._templar.template(template_data, preserve_trailing_newlines=True)
|
||||
ret.append(res)
|
||||
else:
|
||||
|
|
|
@ -82,7 +82,7 @@ class Templar:
|
|||
undefined=StrictUndefined,
|
||||
extensions=self._get_extensions(),
|
||||
finalize=self._finalize,
|
||||
loader=FileSystemLoader('.'),
|
||||
loader=FileSystemLoader(self._basedir),
|
||||
)
|
||||
self.environment.template_class = AnsibleJ2Template
|
||||
|
||||
|
|
Loading…
Reference in a new issue