19 lines
597 B
Python
19 lines
597 B
Python
import json
|
|
from ansible.parsing.yaml.objects import AnsibleVaultEncryptedUnicode
|
|
|
|
|
|
def convert_to_json(data):
|
|
return json.dumps(data, sort_keys=True, indent=2, default=_json_default_serializer)
|
|
|
|
|
|
def _json_default_serializer(value):
|
|
if isinstance(value, bytes):
|
|
return value.decode('utf-8')
|
|
if isinstance(value, str):
|
|
return value
|
|
if isinstance(value, AnsibleVaultEncryptedUnicode):
|
|
return str(value)
|
|
raise TypeError(
|
|
"Unsupported type '%s' used in inventory data "
|
|
"(no support for JSON serializing this type)" % type(value).__name__)
|