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

Fixes #82600
pull/82756/head
Davide Sbetti 3 months ago committed by GitHub
parent 1b209d742e
commit 79ea21a39f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -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).

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

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

Loading…
Cancel
Save