From 9da880182be89a7fdbea3b5424da501542eba4c9 Mon Sep 17 00:00:00 2001 From: Matt Martz Date: Mon, 17 Aug 2020 13:46:13 -0500 Subject: [PATCH] Allow the TOML inventory to dump unsafe. Fixes #71307 (#71309) --- changelogs/fragments/71307-toml-dumps-unsafe.yml | 4 ++++ lib/ansible/plugins/inventory/toml.py | 3 +++ 2 files changed, 7 insertions(+) create mode 100644 changelogs/fragments/71307-toml-dumps-unsafe.yml diff --git a/changelogs/fragments/71307-toml-dumps-unsafe.yml b/changelogs/fragments/71307-toml-dumps-unsafe.yml new file mode 100644 index 00000000000..9b964fc1417 --- /dev/null +++ b/changelogs/fragments/71307-toml-dumps-unsafe.yml @@ -0,0 +1,4 @@ +bugfixes: +- TOML inventory - Ensure we register dump functions for ``AnsibleUnsafe`` to support dumping unsafe values. + Note that the TOML format has no functionality to mark that the data is unsafe for re-consumption. + (https://github.com/ansible/ansible/issues/71307) diff --git a/lib/ansible/plugins/inventory/toml.py b/lib/ansible/plugins/inventory/toml.py index 5d7ce314085..b4c8de1ce67 100644 --- a/lib/ansible/plugins/inventory/toml.py +++ b/lib/ansible/plugins/inventory/toml.py @@ -97,6 +97,7 @@ from ansible.module_utils.six import string_types, text_type from ansible.parsing.yaml.objects import AnsibleSequence, AnsibleUnicode from ansible.plugins.inventory import BaseFileInventoryPlugin from ansible.utils.display import Display +from ansible.utils.unsafe_proxy import AnsibleUnsafeBytes, AnsibleUnsafeText try: import toml @@ -115,6 +116,8 @@ if HAS_TOML and hasattr(toml, 'TomlEncoder'): self.dump_funcs.update({ AnsibleSequence: self.dump_funcs.get(list), AnsibleUnicode: self.dump_funcs.get(str), + AnsibleUnsafeBytes: self.dump_funcs.get(str), + AnsibleUnsafeText: self.dump_funcs.get(str), }) toml_dumps = partial(toml.dumps, encoder=AnsibleTomlEncoder()) else: