summaryrefslogtreecommitdiff
path: root/lib/ansible/template/native_helpers.py
diff options
context:
space:
mode:
authorMartin Krizek <martin.krizek@gmail.com>2021-11-11 20:12:46 +0100
committerGitHub <noreply@github.com>2021-11-12 05:12:46 +1000
commit95e120ed02d108ecf085ba14f0ade2209e94d894 (patch)
tree5d139e18c0c3d3f9fcf7f26f1f20cf90b93c237a /lib/ansible/template/native_helpers.py
parentfe77bc9e3c44d3b340f258397b7081de893c2680 (diff)
downloadansible-95e120ed02d108ecf085ba14f0ade2209e94d894.tar.gz
Keep pre Python 3.10 literal_eval behavior (#76261)
Diffstat (limited to 'lib/ansible/template/native_helpers.py')
-rw-r--r--lib/ansible/template/native_helpers.py7
1 files changed, 6 insertions, 1 deletions
diff --git a/lib/ansible/template/native_helpers.py b/lib/ansible/template/native_helpers.py
index 63d6bdc671..c75d356b38 100644
--- a/lib/ansible/template/native_helpers.py
+++ b/lib/ansible/template/native_helpers.py
@@ -140,6 +140,11 @@ def ansible_native_concat(nodes):
out = ''.join([to_text(_fail_on_undefined(v)) for v in chain(head, nodes)])
try:
- return ast.literal_eval(out)
+ return ast.literal_eval(
+ # In Python 3.10+ ast.literal_eval removes leading spaces/tabs
+ # from the given string. For backwards compatibility we need to
+ # parse the string ourselves without removing leading spaces/tabs.
+ ast.parse(out, mode='eval')
+ )
except (ValueError, SyntaxError, MemoryError):
return out