mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Avoid erroring on host group confusion in keyed groups (#54099)
This commit is contained in:
parent
54be769e8d
commit
f2f11341a3
2 changed files with 21 additions and 1 deletions
|
@ -428,7 +428,7 @@ class Constructable(object):
|
|||
for bare_name in new_raw_group_names:
|
||||
gname = self._sanitize_group_name('%s%s%s' % (prefix, sep, bare_name))
|
||||
result_gname = self.inventory.add_group(gname)
|
||||
self.inventory.add_child(result_gname, host)
|
||||
self.inventory.add_host(host, result_gname)
|
||||
|
||||
if raw_parent_name:
|
||||
parent_name = self._sanitize_group_name(raw_parent_name)
|
||||
|
|
|
@ -93,6 +93,26 @@ def test_keyed_group_empty_construction(inventory_module):
|
|||
assert host.groups == []
|
||||
|
||||
|
||||
def test_keyed_group_host_confusion(inventory_module):
|
||||
inventory_module.inventory.add_host('cow')
|
||||
inventory_module.inventory.add_group('cow')
|
||||
host = inventory_module.inventory.get_host('cow')
|
||||
host.vars['species'] = 'cow'
|
||||
keyed_groups = [
|
||||
{
|
||||
'separator': '',
|
||||
'prefix': '',
|
||||
'key': 'species'
|
||||
}
|
||||
]
|
||||
inventory_module._add_host_to_keyed_groups(
|
||||
keyed_groups, host.vars, host.name, strict=True
|
||||
)
|
||||
group = inventory_module.inventory.groups['cow']
|
||||
# group cow has host of cow
|
||||
assert group.hosts == [host]
|
||||
|
||||
|
||||
def test_keyed_parent_groups(inventory_module):
|
||||
inventory_module.inventory.add_host('web1')
|
||||
inventory_module.inventory.add_host('web2')
|
||||
|
|
Loading…
Reference in a new issue