mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-06 05:12:45 +00:00
Fix error handling when pasing output from dynamic inventory
This commit is contained in:
@@ -23,6 +23,8 @@ import os
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
from collections import Mapping
|
||||
|
||||
from ansible import constants as C
|
||||
from ansible.errors import *
|
||||
from ansible.inventory.host import Host
|
||||
@@ -62,7 +64,16 @@ class InventoryScript:
|
||||
all_hosts = {}
|
||||
|
||||
# not passing from_remote because data from CMDB is trusted
|
||||
self.raw = self._loader.load(self.data)
|
||||
try:
|
||||
self.raw = self._loader.load(self.data)
|
||||
except Exception as e:
|
||||
sys.stderr.write(err + "\n")
|
||||
raise AnsibleError("failed to parse executable inventory script results: %s" % str(e))
|
||||
|
||||
if not isinstance(self.raw, Mapping):
|
||||
sys.stderr.write(err + "\n")
|
||||
raise AnsibleError("failed to parse executable inventory script results: data needs to be formatted as a json dict" )
|
||||
|
||||
self.raw = json_dict_bytes_to_unicode(self.raw)
|
||||
|
||||
all = Group('all')
|
||||
@@ -70,10 +81,6 @@ class InventoryScript:
|
||||
group = None
|
||||
|
||||
|
||||
if 'failed' in self.raw:
|
||||
sys.stderr.write(err + "\n")
|
||||
raise AnsibleError("failed to parse executable inventory script results: %s" % self.raw)
|
||||
|
||||
for (group_name, data) in self.raw.items():
|
||||
|
||||
# in Ansible 1.3 and later, a "_meta" subelement may contain
|
||||
|
||||
Reference in New Issue
Block a user