mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-08-04 05:04:22 -07:00
Merge pull request #13993 from towolf/avoid_json_to_unicode
Avoid recursively checking JSON inventory for Unicode
This commit is contained in:
commit
f594cc0a5b
1 changed files with 8 additions and 4 deletions
|
@ -31,7 +31,7 @@ from ansible.errors import AnsibleError
|
||||||
from ansible.inventory.host import Host
|
from ansible.inventory.host import Host
|
||||||
from ansible.inventory.group import Group
|
from ansible.inventory.group import Group
|
||||||
from ansible.module_utils.basic import json_dict_bytes_to_unicode
|
from ansible.module_utils.basic import json_dict_bytes_to_unicode
|
||||||
from ansible.utils.unicode import to_str
|
from ansible.utils.unicode import to_str, to_unicode
|
||||||
|
|
||||||
|
|
||||||
class InventoryScript:
|
class InventoryScript:
|
||||||
|
@ -58,7 +58,13 @@ class InventoryScript:
|
||||||
if sp.returncode != 0:
|
if sp.returncode != 0:
|
||||||
raise AnsibleError("Inventory script (%s) had an execution error: %s " % (filename,stderr))
|
raise AnsibleError("Inventory script (%s) had an execution error: %s " % (filename,stderr))
|
||||||
|
|
||||||
self.data = stdout
|
# make sure script output is unicode so that json loader will output
|
||||||
|
# unicode strings itself
|
||||||
|
try:
|
||||||
|
self.data = to_unicode(stdout, errors="strict")
|
||||||
|
except Exception as e:
|
||||||
|
raise AnsibleError("inventory data from {0} contained characters that cannot be interpreted as UTF-8: {1}".format(to_str(self.filename), to_str(e)))
|
||||||
|
|
||||||
# see comment about _meta below
|
# see comment about _meta below
|
||||||
self.host_vars_from_top = None
|
self.host_vars_from_top = None
|
||||||
self._parse(stderr)
|
self._parse(stderr)
|
||||||
|
@ -78,8 +84,6 @@ class InventoryScript:
|
||||||
sys.stderr.write(err + "\n")
|
sys.stderr.write(err + "\n")
|
||||||
raise AnsibleError("failed to parse executable inventory script results from {0}: data needs to be formatted as a json dict".format(to_str(self.filename)))
|
raise AnsibleError("failed to parse executable inventory script results from {0}: data needs to be formatted as a json dict".format(to_str(self.filename)))
|
||||||
|
|
||||||
self.raw = json_dict_bytes_to_unicode(self.raw)
|
|
||||||
|
|
||||||
group = None
|
group = None
|
||||||
for (group_name, data) in self.raw.items():
|
for (group_name, data) in self.raw.items():
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue