summaryrefslogtreecommitdiff
path: root/lib/ansible/plugins/action/template.py
diff options
context:
space:
mode:
Diffstat (limited to 'lib/ansible/plugins/action/template.py')
-rw-r--r--lib/ansible/plugins/action/template.py43
1 files changed, 27 insertions, 16 deletions
diff --git a/lib/ansible/plugins/action/template.py b/lib/ansible/plugins/action/template.py
index d2b3df9a..4bfd9670 100644
--- a/lib/ansible/plugins/action/template.py
+++ b/lib/ansible/plugins/action/template.py
@@ -10,10 +10,19 @@ import shutil
import stat
import tempfile
+from jinja2.defaults import (
+ BLOCK_END_STRING,
+ BLOCK_START_STRING,
+ COMMENT_END_STRING,
+ COMMENT_START_STRING,
+ VARIABLE_END_STRING,
+ VARIABLE_START_STRING,
+)
+
from ansible import constants as C
from ansible.config.manager import ensure_type
from ansible.errors import AnsibleError, AnsibleFileNotFound, AnsibleAction, AnsibleActionFail
-from ansible.module_utils._text import to_bytes, to_text, to_native
+from ansible.module_utils.common.text.converters import to_bytes, to_text, to_native
from ansible.module_utils.parsing.convert_bool import boolean
from ansible.module_utils.six import string_types
from ansible.plugins.action import ActionBase
@@ -57,12 +66,12 @@ class ActionModule(ActionBase):
dest = self._task.args.get('dest', None)
state = self._task.args.get('state', None)
newline_sequence = self._task.args.get('newline_sequence', self.DEFAULT_NEWLINE_SEQUENCE)
- variable_start_string = self._task.args.get('variable_start_string', None)
- variable_end_string = self._task.args.get('variable_end_string', None)
- block_start_string = self._task.args.get('block_start_string', None)
- block_end_string = self._task.args.get('block_end_string', None)
- comment_start_string = self._task.args.get('comment_start_string', None)
- comment_end_string = self._task.args.get('comment_end_string', None)
+ variable_start_string = self._task.args.get('variable_start_string', VARIABLE_START_STRING)
+ variable_end_string = self._task.args.get('variable_end_string', VARIABLE_END_STRING)
+ block_start_string = self._task.args.get('block_start_string', BLOCK_START_STRING)
+ block_end_string = self._task.args.get('block_end_string', BLOCK_END_STRING)
+ comment_start_string = self._task.args.get('comment_start_string', COMMENT_START_STRING)
+ comment_end_string = self._task.args.get('comment_end_string', COMMENT_END_STRING)
output_encoding = self._task.args.get('output_encoding', 'utf-8') or 'utf-8'
wrong_sequences = ["\\n", "\\r", "\\r\\n"]
@@ -129,16 +138,18 @@ class ActionModule(ActionBase):
templar = self._templar.copy_with_new_env(environment_class=AnsibleEnvironment,
searchpath=searchpath,
newline_sequence=newline_sequence,
- block_start_string=block_start_string,
- block_end_string=block_end_string,
- variable_start_string=variable_start_string,
- variable_end_string=variable_end_string,
- comment_start_string=comment_start_string,
- comment_end_string=comment_end_string,
- trim_blocks=trim_blocks,
- lstrip_blocks=lstrip_blocks,
available_variables=temp_vars)
- resultant = templar.do_template(template_data, preserve_trailing_newlines=True, escape_backslashes=False)
+ overrides = dict(
+ block_start_string=block_start_string,
+ block_end_string=block_end_string,
+ variable_start_string=variable_start_string,
+ variable_end_string=variable_end_string,
+ comment_start_string=comment_start_string,
+ comment_end_string=comment_end_string,
+ trim_blocks=trim_blocks,
+ lstrip_blocks=lstrip_blocks
+ )
+ resultant = templar.do_template(template_data, preserve_trailing_newlines=True, escape_backslashes=False, overrides=overrides)
except AnsibleAction:
raise
except Exception as e: