1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

warn on bad keys in group

This commit is contained in:
Brian Coca 2017-10-09 16:20:48 -04:00 committed by Brian Coca
parent 8415d2e60a
commit 1bf09a7d84

View file

@ -118,19 +118,22 @@ class InventoryModule(BaseFileInventoryPlugin):
raise AnsibleParserError('Invalid "%s" entry for "%s" group, requires a dictionary, found "%s" instead.' %
(section, group, type(group_data[section])))
if group_data.get('vars', False):
for var in group_data['vars']:
self.inventory.set_variable(group, var, group_data['vars'][var])
for key in group_data:
if key == 'vars':
for var in group_data['vars']:
self.inventory.set_variable(group, var, group_data['vars'][var])
if group_data.get('children', False):
for subgroup in group_data['children']:
self._parse_group(subgroup, group_data['children'][subgroup])
self.inventory.add_child(group, subgroup)
elif key == 'children':
for subgroup in group_data['children']:
self._parse_group(subgroup, group_data['children'][subgroup])
self.inventory.add_child(group, subgroup)
if group_data.get('hosts', False):
for host_pattern in group_data['hosts']:
hosts, port = self._parse_host(host_pattern)
self.populate_host_vars(hosts, group_data['hosts'][host_pattern] or {}, group, port)
elif key == 'hosts':
for host_pattern in group_data['hosts']:
hosts, port = self._parse_host(host_pattern)
self.populate_host_vars(hosts, group_data['hosts'][host_pattern] or {}, group, port)
else:
self.display.warn('Skipping unexpected key (%s) in group (%s), only "vars", "children" and "hosts" are valid' % (key, group))
def _parse_host(self, host_pattern):
'''