Allow the TOML inventory to dump unsafe. Fixes #71307 (#71309)

This commit is contained in:
Matt Martz 2020-08-17 13:46:13 -05:00 committed by GitHub
parent 959af7d90b
commit 9da880182b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 0 deletions

View file

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

View file

@ -97,6 +97,7 @@ from ansible.module_utils.six import string_types, text_type
from ansible.parsing.yaml.objects import AnsibleSequence, AnsibleUnicode from ansible.parsing.yaml.objects import AnsibleSequence, AnsibleUnicode
from ansible.plugins.inventory import BaseFileInventoryPlugin from ansible.plugins.inventory import BaseFileInventoryPlugin
from ansible.utils.display import Display from ansible.utils.display import Display
from ansible.utils.unsafe_proxy import AnsibleUnsafeBytes, AnsibleUnsafeText
try: try:
import toml import toml
@ -115,6 +116,8 @@ if HAS_TOML and hasattr(toml, 'TomlEncoder'):
self.dump_funcs.update({ self.dump_funcs.update({
AnsibleSequence: self.dump_funcs.get(list), AnsibleSequence: self.dump_funcs.get(list),
AnsibleUnicode: self.dump_funcs.get(str), 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()) toml_dumps = partial(toml.dumps, encoder=AnsibleTomlEncoder())
else: else: