Fix error when templating an unsafe string leading to a type error in Python (#82675)

Fixes #82600
This commit is contained in:
Davide Sbetti 2024-02-26 15:39:07 +01:00 committed by GitHub
parent 1b209d742e
commit 79ea21a39f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 9 additions and 2 deletions

View File

@ -0,0 +1,2 @@
bugfixes:
- template - Fix error when templating an unsafe string which corresponds to an invalid type in Python (https://github.com/ansible/ansible/issues/82600).

View File

@ -65,7 +65,7 @@ def ansible_eval_concat(nodes):
)
)
)
except (ValueError, SyntaxError, MemoryError):
except (TypeError, ValueError, SyntaxError, MemoryError):
pass
return out
@ -127,7 +127,7 @@ def ansible_native_concat(nodes):
# parse the string ourselves without removing leading spaces/tabs.
ast.parse(out, mode='eval')
)
except (ValueError, SyntaxError, MemoryError):
except (TypeError, ValueError, SyntaxError, MemoryError):
return out
if isinstance(evaled, string_types):

View File

@ -3,6 +3,7 @@
vars:
nottemplated: this should not be seen
imunsafe: !unsafe '{{ nottemplated }}'
unsafe_set: !unsafe '{{ "test" }}'
tasks:
- set_fact:
@ -12,11 +13,15 @@
- set_fact:
this_always_safe: '{{ imunsafe }}'
- set_fact:
this_unsafe_set: "{{ unsafe_set }}"
- name: ensure nothing was templated
assert:
that:
- this_always_safe == imunsafe
- imunsafe == this_was_unsafe.strip()
- unsafe_set == this_unsafe_set.strip()
- hosts: localhost