always template when called from template (#18490)
* Have template action plugin call do_template
Avoids all the magic done for 'inline templating' for ansible plays.
renamed _do_template to do_template in templar to make externally accessible.
fixes #18192
* added backwards compat as per feedback
(cherry picked from commit bd70397e24
)
This commit is contained in:
parent
7602a2a030
commit
42fb088807
2 changed files with 6 additions and 3 deletions
|
@ -127,7 +127,7 @@ class ActionModule(ActionBase):
|
||||||
|
|
||||||
old_vars = self._templar._available_variables
|
old_vars = self._templar._available_variables
|
||||||
self._templar.set_available_variables(temp_vars)
|
self._templar.set_available_variables(temp_vars)
|
||||||
resultant = self._templar.template(template_data, preserve_trailing_newlines=True, escape_backslashes=False, convert_data=False)
|
resultant = self._templar.do_template(template_data, preserve_trailing_newlines=True, escape_backslashes=False)
|
||||||
self._templar.set_available_variables(old_vars)
|
self._templar.set_available_variables(old_vars)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
result['failed'] = True
|
result['failed'] = True
|
||||||
|
|
|
@ -328,7 +328,7 @@ class Templar:
|
||||||
if cache and sha1_hash in self._cached_result:
|
if cache and sha1_hash in self._cached_result:
|
||||||
result = self._cached_result[sha1_hash]
|
result = self._cached_result[sha1_hash]
|
||||||
else:
|
else:
|
||||||
result = self._do_template(variable, preserve_trailing_newlines=preserve_trailing_newlines, escape_backslashes=escape_backslashes, fail_on_undefined=fail_on_undefined, overrides=overrides)
|
result = self.do_template(variable, preserve_trailing_newlines=preserve_trailing_newlines, escape_backslashes=escape_backslashes, fail_on_undefined=fail_on_undefined, overrides=overrides)
|
||||||
if convert_data and not self._no_type_regex.match(variable):
|
if convert_data and not self._no_type_regex.match(variable):
|
||||||
# if this looks like a dictionary or list, convert it to such using the safe_eval method
|
# if this looks like a dictionary or list, convert it to such using the safe_eval method
|
||||||
if (result.startswith("{") and not result.startswith(self.environment.variable_start_string)) or \
|
if (result.startswith("{") and not result.startswith(self.environment.variable_start_string)) or \
|
||||||
|
@ -451,7 +451,7 @@ class Templar:
|
||||||
else:
|
else:
|
||||||
raise AnsibleError("lookup plugin (%s) not found" % name)
|
raise AnsibleError("lookup plugin (%s) not found" % name)
|
||||||
|
|
||||||
def _do_template(self, data, preserve_trailing_newlines=True, escape_backslashes=True, fail_on_undefined=None, overrides=None):
|
def do_template(self, data, preserve_trailing_newlines=True, escape_backslashes=True, fail_on_undefined=None, overrides=None):
|
||||||
# For preserving the number of input newlines in the output (used
|
# For preserving the number of input newlines in the output (used
|
||||||
# later in this method)
|
# later in this method)
|
||||||
data_newlines = _count_newlines_from_end(data)
|
data_newlines = _count_newlines_from_end(data)
|
||||||
|
@ -537,3 +537,6 @@ class Templar:
|
||||||
else:
|
else:
|
||||||
#TODO: return warning about undefined var
|
#TODO: return warning about undefined var
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
# for backwards compatibility in case anyone is using old private method directly
|
||||||
|
_do_template = do_template
|
||||||
|
|
Loading…
Reference in a new issue