Inventory groups should be under children key
When writing ansible inventory files as yaml, we should be using add them under the children key per the official documentation: https://docs.ansible.com/ansible/latest/user_guide/intro_inventory.html#hosts-and-groups This is the first step to allowing groups of groups for an inventory. Change-Id: Id1e14d0364dd06af0371ca027031e46fb5f73e92 Signed-off-by: Paul Belanger <pabelanger@redhat.com>
This commit is contained in:
parent
2a67365a7c
commit
5d26bf8407
|
@ -89,14 +89,16 @@ class TestInventory(ZuulTestCase):
|
||||||
|
|
||||||
all_nodes = ('controller', 'compute1', 'compute2')
|
all_nodes = ('controller', 'compute1', 'compute2')
|
||||||
self.assertIn('all', inventory)
|
self.assertIn('all', inventory)
|
||||||
|
self.assertIn('children', inventory['all'])
|
||||||
self.assertIn('hosts', inventory['all'])
|
self.assertIn('hosts', inventory['all'])
|
||||||
self.assertIn('vars', inventory['all'])
|
self.assertIn('vars', inventory['all'])
|
||||||
for group_name in ('ceph-osd', 'ceph-monitor'):
|
for group_name in ('ceph-osd', 'ceph-monitor'):
|
||||||
self.assertIn(group_name, inventory)
|
self.assertIn(group_name, inventory['all']['children'])
|
||||||
for node_name in all_nodes:
|
for node_name in all_nodes:
|
||||||
self.assertIn(node_name, inventory['all']['hosts'])
|
self.assertIn(node_name, inventory['all']['hosts'])
|
||||||
self.assertIn(node_name,
|
self.assertIn(node_name,
|
||||||
inventory['ceph-monitor']['hosts'])
|
inventory['all']['children']
|
||||||
|
['ceph-monitor']['hosts'])
|
||||||
self.assertIn('zuul', inventory['all']['vars'])
|
self.assertIn('zuul', inventory['all']['vars'])
|
||||||
z_vars = inventory['all']['vars']['zuul']
|
z_vars = inventory['all']['vars']['zuul']
|
||||||
self.assertIn('executor', z_vars)
|
self.assertIn('executor', z_vars)
|
||||||
|
|
|
@ -565,15 +565,19 @@ def make_inventory_dict(nodes, args, all_vars):
|
||||||
}
|
}
|
||||||
|
|
||||||
for group in args['groups']:
|
for group in args['groups']:
|
||||||
|
if 'children' not in inventory['all']:
|
||||||
|
inventory['all']['children'] = dict()
|
||||||
group_hosts = {}
|
group_hosts = {}
|
||||||
for node_name in group['nodes']:
|
for node_name in group['nodes']:
|
||||||
group_hosts[node_name] = None
|
group_hosts[node_name] = None
|
||||||
group_vars = args['group_vars'].get(group['name'], {}).copy()
|
group_vars = args['group_vars'].get(group['name'], {}).copy()
|
||||||
check_varnames(group_vars)
|
check_varnames(group_vars)
|
||||||
inventory[group['name']] = {
|
|
||||||
'hosts': group_hosts,
|
inventory['all']['children'].update({
|
||||||
'vars': group_vars,
|
group['name']: {
|
||||||
}
|
'hosts': group_hosts,
|
||||||
|
'vars': group_vars,
|
||||||
|
}})
|
||||||
|
|
||||||
return inventory
|
return inventory
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue