mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Slightly friendlier error on missing hosts file, slightly friendlier error on inventory script returning invalid syntax
(or if inventory is non-script and accidentally executable).
This commit is contained in:
parent
1163c23c35
commit
a894791767
2 changed files with 16 additions and 6 deletions
|
@ -93,7 +93,7 @@ class Inventory(object):
|
|||
else:
|
||||
raise errors.AnsibleError("YAML inventory support is deprecated in 0.6 and removed in 0.7, see the migration script in examples/scripts in the git checkout")
|
||||
else:
|
||||
raise errors.AnsibleError("No valid hosts inventory file found")
|
||||
raise errors.AnsibleError("Unable to find an inventory file, specify one with -i ?")
|
||||
|
||||
def _match(self, str, pattern_str):
|
||||
if pattern_str.startswith('~'):
|
||||
|
|
|
@ -39,27 +39,37 @@ class InventoryScript(object):
|
|||
self.groups = self._parse()
|
||||
|
||||
def _parse(self):
|
||||
all_hosts = {}
|
||||
|
||||
self.raw = utils.parse_json(self.data)
|
||||
all=Group('all')
|
||||
groups = dict(all=all)
|
||||
group = None
|
||||
all_hosts = {}
|
||||
self.raw = utils.parse_json(self.data)
|
||||
all = Group('all')
|
||||
groups = dict(all=all)
|
||||
group = None
|
||||
|
||||
if 'failed' in self.raw:
|
||||
raise errors.AnsibleError("failed to parse executable inventory script results")
|
||||
|
||||
for (group_name, data) in self.raw.items():
|
||||
|
||||
group = groups[group_name] = Group(group_name)
|
||||
host = None
|
||||
|
||||
if not isinstance(data, dict):
|
||||
data = {'hosts': data}
|
||||
|
||||
if 'hosts' in data:
|
||||
|
||||
for hostname in data['hosts']:
|
||||
if not hostname in all_hosts:
|
||||
all_hosts[hostname] = Host(hostname)
|
||||
host = all_hosts[hostname]
|
||||
group.add_host(host)
|
||||
|
||||
if 'vars' in data:
|
||||
for k, v in data['vars'].iteritems():
|
||||
group.set_variable(k, v)
|
||||
all.add_child_group(group)
|
||||
|
||||
# Separate loop to ensure all groups are defined
|
||||
for (group_name, data) in self.raw.items():
|
||||
if isinstance(data, dict) and 'children' in data:
|
||||
|
|
Loading…
Reference in a new issue