mirror of
https://github.com/ansible/awx.git
synced 2026-01-10 15:32:07 -03:30
Update the inventory script to follow the new variabledata schema. This is untested and may need revisions.
This commit is contained in:
parent
ce7112e08a
commit
4a2673482b
@ -44,12 +44,14 @@ class Command(NoArgsCommand):
|
||||
groups = {}
|
||||
for group in inventory.groups.all():
|
||||
# FIXME: Check if group is active?
|
||||
|
||||
group_info = {
|
||||
'hosts': list(group.hosts.values_list('name', flat=True)),
|
||||
# FIXME: Include host vars here?
|
||||
'vars': dict(group.variable_data.values_list('name', 'data')),
|
||||
'children': list(group.children.values_list('name', flat=True)),
|
||||
}
|
||||
if group.variables is not None:
|
||||
group_info['vars'] = json.loads(group.variables.data)
|
||||
|
||||
group_info = dict(filter(lambda x: bool(x[1]), group_info.items()))
|
||||
if group_info.keys() in ([], ['hosts']):
|
||||
groups[group.name] = group_info.get('hosts', [])
|
||||
@ -65,9 +67,11 @@ class Command(NoArgsCommand):
|
||||
host = inventory.hosts.get(name=hostname)
|
||||
except Host.DoesNotExist:
|
||||
raise CommandError('Host %s not found in the given inventory' % hostname)
|
||||
hostvars = dict(host.variable_data.values_list('name', 'data'))
|
||||
hostvars = {}
|
||||
if host.variables is not None:
|
||||
hostvars = json.loads(host.variables.data)
|
||||
# FIXME: Do we also need to include variables defined for groups of which
|
||||
# this host is a member?
|
||||
# this host is a member? (MPD: pretty sure we don't!)
|
||||
self.stdout.write(json.dumps(hostvars, indent=indent))
|
||||
|
||||
def handle_noargs(self, **options):
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user