From bd70397e246e4a1d9d892964e5d66a452c08a676 Mon Sep 17 00:00:00 2001 From: Brian Coca Date: Tue, 15 Nov 2016 15:16:46 -0500 Subject: [PATCH] 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 --- lib/ansible/plugins/action/template.py | 2 +- lib/ansible/template/__init__.py | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/ansible/plugins/action/template.py b/lib/ansible/plugins/action/template.py index 488b53ba38b..34f452f7a3b 100644 --- a/lib/ansible/plugins/action/template.py +++ b/lib/ansible/plugins/action/template.py @@ -127,7 +127,7 @@ class ActionModule(ActionBase): old_vars = self._templar._available_variables 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) except Exception as e: result['failed'] = True diff --git a/lib/ansible/template/__init__.py b/lib/ansible/template/__init__.py index 2eec3bf3c7c..f0863eee47a 100644 --- a/lib/ansible/template/__init__.py +++ b/lib/ansible/template/__init__.py @@ -328,7 +328,7 @@ class Templar: if cache and sha1_hash in self._cached_result: result = self._cached_result[sha1_hash] 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 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 \ @@ -451,7 +451,7 @@ class Templar: else: 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 # later in this method) data_newlines = _count_newlines_from_end(data) @@ -537,3 +537,6 @@ class Templar: else: #TODO: return warning about undefined var return data + + # for backwards compatibility in case anyone is using old private method directly + _do_template = do_template