mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-25 06:10:22 -07:00
Allow inventory scripts to define groups of groups and group vars
This commit is contained in:
parent
b8d6dec5ad
commit
8d309e0fa3
3 changed files with 43 additions and 20 deletions
|
@ -45,15 +45,25 @@ class InventoryScript(object):
|
|||
all=Group('all')
|
||||
groups = dict(all=all)
|
||||
group = None
|
||||
for (group_name, hosts) in self.raw.items():
|
||||
for (group_name, data) in self.raw.items():
|
||||
group = groups[group_name] = Group(group_name)
|
||||
host = None
|
||||
for hostname in hosts:
|
||||
if not hostname in all_hosts:
|
||||
all_hosts[hostname] = Host(hostname)
|
||||
host = all_hosts[hostname]
|
||||
group.add_host(host)
|
||||
# FIXME: hack shouldn't be needed
|
||||
all.add_host(host)
|
||||
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:
|
||||
for child_name in data['children']:
|
||||
if child_name in groups:
|
||||
groups[group_name].add_child_group(groups[child_name])
|
||||
return groups
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue