mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-24 11:21:25 -07:00
Enabled unsafe and vault in JSON (#38759)
* allow to load json marked as unsafe or vault * centralized json code/decode, add vault support * use generics to allow for more varied inputs * allow inventory to dump vault w/o decrypting * override simplejson also * add entry for unsafe also * load vaulted and unsafe json, support unvaulting if secrets provided
This commit is contained in:
parent
ff16e993be
commit
cbb6a7f4e8
5 changed files with 99 additions and 56 deletions
|
@ -13,10 +13,10 @@ from yaml import YAMLError
|
|||
|
||||
from ansible.errors import AnsibleParserError
|
||||
from ansible.errors.yaml_strings import YAML_SYNTAX_ERROR
|
||||
from ansible.module_utils.six import text_type
|
||||
from ansible.module_utils._text import to_native
|
||||
from ansible.parsing.yaml.loader import AnsibleLoader
|
||||
from ansible.parsing.yaml.objects import AnsibleBaseYAMLObject
|
||||
from ansible.parsing.ajson import AnsibleJSONDecoder
|
||||
|
||||
|
||||
__all__ = ('from_yaml',)
|
||||
|
@ -62,9 +62,12 @@ def from_yaml(data, file_name='<string>', show_content=True, vault_secrets=None)
|
|||
new_data = None
|
||||
|
||||
try:
|
||||
# we first try to load this data as JSON. Fixes issues with extra vars json strings not
|
||||
# being parsed correctly by the yaml parser
|
||||
new_data = json.loads(data)
|
||||
# in case we have to deal with vaults
|
||||
AnsibleJSONDecoder.set_secrets(vault_secrets)
|
||||
|
||||
# we first try to load this data as JSON.
|
||||
# Fixes issues with extra vars json strings not being parsed correctly by the yaml parser
|
||||
new_data = json.loads(data, cls=AnsibleJSONDecoder)
|
||||
except Exception:
|
||||
# must not be JSON, let the rest try
|
||||
try:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue