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:
Brian Coca 2018-05-09 14:01:51 -04:00 committed by GitHub
parent ff16e993be
commit cbb6a7f4e8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 99 additions and 56 deletions

View file

@ -193,8 +193,9 @@ class InventoryCLI(CLI):
from ansible.parsing.yaml.dumper import AnsibleDumper
results = yaml.dump(stuff, Dumper=AnsibleDumper, default_flow_style=False)
else:
from ansible.module_utils.basic import jsonify
results = jsonify(stuff, sort_keys=True, indent=4)
import json
from ansible.parsing.ajson import AnsibleJSONEncoder
results = json.dumps(stuff, cls=AnsibleJSONEncoder, sort_keys=True, indent=4)
return results
@ -210,9 +211,9 @@ class InventoryCLI(CLI):
except AttributeError:
try:
if isinstance(entity, Host):
data.update(plugin.get_host_vars(entity.name))
data = combine_vars(data, plugin.get_host_vars(entity.name))
else:
data.update(plugin.get_group_vars(entity.name))
data = combine_vars(data, plugin.get_group_vars(entity.name))
except AttributeError:
if hasattr(plugin, 'run'):
raise AnsibleError("Cannot use v1 type vars plugin %s from %s" % (plugin._load_name, plugin._original_path))