Browse Source

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>
changes/06/559406/4
Paul Belanger 3 years ago
committed by James E. Blair
parent
commit
5d26bf8407
2 changed files with 12 additions and 6 deletions
  1. +4
    -2
      tests/unit/test_inventory.py
  2. +8
    -4
      zuul/executor/server.py

+ 4
- 2
tests/unit/test_inventory.py View File

@ -89,14 +89,16 @@ class TestInventory(ZuulTestCase):
all_nodes = ('controller', 'compute1', 'compute2')
self.assertIn('all', inventory)
self.assertIn('children', inventory['all'])
self.assertIn('hosts', inventory['all'])
self.assertIn('vars', inventory['all'])
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:
self.assertIn(node_name, inventory['all']['hosts'])
self.assertIn(node_name,
inventory['ceph-monitor']['hosts'])
inventory['all']['children']
['ceph-monitor']['hosts'])
self.assertIn('zuul', inventory['all']['vars'])
z_vars = inventory['all']['vars']['zuul']
self.assertIn('executor', z_vars)


+ 8
- 4
zuul/executor/server.py View File

@ -565,15 +565,19 @@ def make_inventory_dict(nodes, args, all_vars):
}
for group in args['groups']:
if 'children' not in inventory['all']:
inventory['all']['children'] = dict()
group_hosts = {}
for node_name in group['nodes']:
group_hosts[node_name] = None
group_vars = args['group_vars'].get(group['name'], {}).copy()
check_varnames(group_vars)
inventory[group['name']] = {
'hosts': group_hosts,
'vars': group_vars,
}
inventory['all']['children'].update({
group['name']: {
'hosts': group_hosts,
'vars': group_vars,
}})
return inventory


Loading…
Cancel
Save