From 1bf09a7d849b04476e148ef89a565c682eb3c8c1 Mon Sep 17 00:00:00 2001 From: Brian Coca Date: Mon, 9 Oct 2017 16:20:48 -0400 Subject: [PATCH] warn on bad keys in group --- lib/ansible/plugins/inventory/yaml.py | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/lib/ansible/plugins/inventory/yaml.py b/lib/ansible/plugins/inventory/yaml.py index 97d50fc711..210c290808 100644 --- a/lib/ansible/plugins/inventory/yaml.py +++ b/lib/ansible/plugins/inventory/yaml.py @@ -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): '''