Fixed bug when all group vars are not included

This commit is contained in:
Rick Stokkingreef 2018-11-06 14:26:36 +01:00
parent 3fef7acaa8
commit f916bd7994
2 changed files with 27 additions and 0 deletions

View File

@ -297,6 +297,9 @@ class Inventory(CommonModelNameNotUnique, ResourceMixin, RelatedJobsMixin):
if not (data.get(group_name, {}).get('hosts', []) or data.get(group_name, {}).get('children', [])):
data.pop(group_name)
# Add the all group
data['all'] = all_group
if hostvars:
data.setdefault('_meta', dict())
data['_meta'].setdefault('hostvars', dict())

View File

@ -38,6 +38,30 @@ class TestInventoryScript:
'remote_tower_id': host.id
}
def test_all_group(self, inventory):
inventory.groups.create(name='all', variables={'a1': 'a1'})
g1 = inventory.groups.create(name='g1', variables={'v1': 'v1'})
h1 = inventory.hosts.create(name='h1')
inventory.hosts.create(name='h2')
# h1 becomes member of g1 group
g1.hosts.add(h1)
# make sure we return a1 details in output
data = inventory.get_script_data(hostvars=1)
assert 'all' in data
assert 'g1' in data
assert data['g1'] == {
'hosts': ['h1'],
'children': [],
'vars': {'v1': 'v1'}
}
assert data['all'] == {
'hosts': ['h2'],
'children': ['g1'],
'vars': {'a1': 'a1'}
}
def test_grandparent_group(self, inventory):
g1 = inventory.groups.create(name='g1', variables={'v1': 'v1'})
g2 = inventory.groups.create(name='g2', variables={'v2': 'v2'})