|
|
|
@ -45,6 +45,7 @@ _raw:
|
|
|
|
description: file(s) content after templating
|
|
|
|
description: file(s) content after templating
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from copy import deepcopy
|
|
|
|
import os
|
|
|
|
import os
|
|
|
|
|
|
|
|
|
|
|
|
from ansible.errors import AnsibleError
|
|
|
|
from ansible.errors import AnsibleError
|
|
|
|
@ -67,6 +68,8 @@ class LookupModule(LookupBase):
|
|
|
|
variable_start_string = kwargs.get('variable_start_string', None)
|
|
|
|
variable_start_string = kwargs.get('variable_start_string', None)
|
|
|
|
variable_end_string = kwargs.get('variable_end_string', None)
|
|
|
|
variable_end_string = kwargs.get('variable_end_string', None)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
old_vars = self._templar._available_variables
|
|
|
|
|
|
|
|
|
|
|
|
for term in terms:
|
|
|
|
for term in terms:
|
|
|
|
display.debug("File lookup term: %s" % term)
|
|
|
|
display.debug("File lookup term: %s" % term)
|
|
|
|
|
|
|
|
|
|
|
|
@ -99,7 +102,7 @@ class LookupModule(LookupBase):
|
|
|
|
# plus some added by ansible (e.g., template_{path,mtime}),
|
|
|
|
# plus some added by ansible (e.g., template_{path,mtime}),
|
|
|
|
# plus anything passed to the lookup with the template_vars=
|
|
|
|
# plus anything passed to the lookup with the template_vars=
|
|
|
|
# argument.
|
|
|
|
# argument.
|
|
|
|
vars = variables.copy()
|
|
|
|
vars = deepcopy(variables)
|
|
|
|
vars.update(generate_ansible_template_vars(lookupfile))
|
|
|
|
vars.update(generate_ansible_template_vars(lookupfile))
|
|
|
|
vars.update(lookup_template_vars)
|
|
|
|
vars.update(lookup_template_vars)
|
|
|
|
self._templar.set_available_variables(vars)
|
|
|
|
self._templar.set_available_variables(vars)
|
|
|
|
@ -107,8 +110,12 @@ class LookupModule(LookupBase):
|
|
|
|
# do the templating
|
|
|
|
# do the templating
|
|
|
|
res = self._templar.template(template_data, preserve_trailing_newlines=True,
|
|
|
|
res = self._templar.template(template_data, preserve_trailing_newlines=True,
|
|
|
|
convert_data=convert_data_p, escape_backslashes=False)
|
|
|
|
convert_data=convert_data_p, escape_backslashes=False)
|
|
|
|
|
|
|
|
|
|
|
|
ret.append(res)
|
|
|
|
ret.append(res)
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
raise AnsibleError("the template file %s could not be found for the lookup" % term)
|
|
|
|
raise AnsibleError("the template file %s could not be found for the lookup" % term)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# restore old variables
|
|
|
|
|
|
|
|
self._templar.set_available_variables(old_vars)
|
|
|
|
|
|
|
|
|
|
|
|
return ret
|
|
|
|
return ret
|
|
|
|
|