diff --git a/changelogs/fragments/320_unsafe_text.yml b/changelogs/fragments/320_unsafe_text.yml new file mode 100644 index 00000000000..aa0621d0858 --- /dev/null +++ b/changelogs/fragments/320_unsafe_text.yml @@ -0,0 +1,2 @@ +bugfixes: +- json_query - handle ``AnsibleUnicode`` and ``AnsibleUnsafeText`` (https://github.com/ansible-collections/community.general/issues/320). diff --git a/plugins/filter/json_query.py b/plugins/filter/json_query.py index 123d929bbaf..972109a0458 100644 --- a/plugins/filter/json_query.py +++ b/plugins/filter/json_query.py @@ -35,6 +35,9 @@ def json_query(data, expr): raise AnsibleError('You need to install "jmespath" prior to running ' 'json_query filter') + # Hack to handle Ansible String Types + # See issue: https://github.com/ansible-collections/community.general/issues/320 + jmespath.functions.REVERSE_TYPES_MAP['string'] = jmespath.functions.REVERSE_TYPES_MAP['string'] + ('AnsibleUnicode', 'AnsibleUnsafeText', ) try: return jmespath.search(expr, data) except jmespath.exceptions.JMESPathError as e: