1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00
This commit is contained in:
Toshio Kuratomi 2016-01-06 15:46:42 -08:00
parent 46903c80fa
commit d26d76ea58

View file

@ -63,7 +63,6 @@ class InventoryScript:
self.host_vars_from_top = None self.host_vars_from_top = None
self._parse(stderr) self._parse(stderr)
def _parse(self, err): def _parse(self, err):
all_hosts = {} all_hosts = {}
@ -73,7 +72,7 @@ class InventoryScript:
self.raw = self._loader.load(self.data) self.raw = self._loader.load(self.data)
except Exception as e: except Exception as e:
sys.stderr.write(err + "\n") sys.stderr.write(err + "\n")
raise AnsibleError("failed to parse executable inventory script results from {0}: {1}".format(to_str(self.filename_, to_str(e))) raise AnsibleError("failed to parse executable inventory script results from {0}: {1}".format(to_str(self.filename), to_str(e)))
if not isinstance(self.raw, Mapping): if not isinstance(self.raw, Mapping):
sys.stderr.write(err + "\n") sys.stderr.write(err + "\n")
@ -113,7 +112,7 @@ class InventoryScript:
"data for the host list:\n %s" % (group_name, data)) "data for the host list:\n %s" % (group_name, data))
for hostname in data['hosts']: for hostname in data['hosts']:
if not hostname in all_hosts: if hostname not in all_hosts:
all_hosts[hostname] = Host(hostname) all_hosts[hostname] = Host(hostname)
host = all_hosts[hostname] host = all_hosts[hostname]
group.add_host(host) group.add_host(host)
@ -149,7 +148,6 @@ class InventoryScript:
got = self.host_vars_from_top.get(host.name, {}) got = self.host_vars_from_top.get(host.name, {})
return got return got
cmd = [self.filename, "--host", host.name] cmd = [self.filename, "--host", host.name]
try: try:
sp = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) sp = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
@ -162,4 +160,3 @@ class InventoryScript:
return json_dict_bytes_to_unicode(self._loader.load(out)) return json_dict_bytes_to_unicode(self._loader.load(out))
except ValueError: except ValueError:
raise AnsibleError("could not parse post variable response: %s, %s" % (cmd, out)) raise AnsibleError("could not parse post variable response: %s, %s" % (cmd, out))