From 550e021cd2628a6460ed32395297ffed38074396 Mon Sep 17 00:00:00 2001 From: Martin Krizek Date: Tue, 24 Mar 2020 12:03:31 +0100 Subject: [PATCH] ansible_native_concat: use to_text rather than jinja2's text_type (#68038) jinja2._compat.text_type has been removed in jinja2's master branch so use ansible's to_text instead. --- ...le_native_concat-use-to_text-rather-than-text_type.yml | 2 ++ lib/ansible/template/native_helpers.py | 8 ++++---- 2 files changed, 6 insertions(+), 4 deletions(-) create mode 100644 changelogs/fragments/ansible_native_concat-use-to_text-rather-than-text_type.yml diff --git a/changelogs/fragments/ansible_native_concat-use-to_text-rather-than-text_type.yml b/changelogs/fragments/ansible_native_concat-use-to_text-rather-than-text_type.yml new file mode 100644 index 00000000000..fd8a612e60e --- /dev/null +++ b/changelogs/fragments/ansible_native_concat-use-to_text-rather-than-text_type.yml @@ -0,0 +1,2 @@ +minor_changes: + - ansible_native_concat() - use ``to_text`` function rather than Jinja2's ``text_type`` which has been removed in Jinja2 master branch. diff --git a/lib/ansible/template/native_helpers.py b/lib/ansible/template/native_helpers.py index 11c14b7fa12..e0df87dcb0d 100644 --- a/lib/ansible/template/native_helpers.py +++ b/lib/ansible/template/native_helpers.py @@ -10,9 +10,9 @@ from ast import literal_eval from itertools import islice, chain import types -from jinja2._compat import text_type - from jinja2.runtime import StrictUndefined + +from ansible.module_utils._text import to_text from ansible.parsing.yaml.objects import AnsibleVaultEncryptedUnicode @@ -46,7 +46,7 @@ def ansible_native_concat(nodes): # (see Jinja2 source of StrictUndefined to get up to date info) # Otherwise the undefined error would be raised on the next access which might not be properly handled. # See https://github.com/ansible/ansible/issues/52158 - # We do that only here because it is taken care of by text_type() in the else block below already. + # We do that only here because it is taken care of by to_text() in the else block below already. str(out) # short circuit literal_eval when possible @@ -57,7 +57,7 @@ def ansible_native_concat(nodes): nodes = chain(head, nodes) # Stringifying the nodes is important as it takes care of # StrictUndefined by side-effect - by raising an exception. - out = u''.join([text_type(v) for v in nodes]) + out = u''.join([to_text(v) for v in nodes]) try: return literal_eval(out)