diff --git a/lib/ansible/plugins/inventory/yaml.py b/lib/ansible/plugins/inventory/yaml.py index 3934c2167f3..520d8543a3f 100644 --- a/lib/ansible/plugins/inventory/yaml.py +++ b/lib/ansible/plugins/inventory/yaml.py @@ -126,16 +126,16 @@ class InventoryModule(BaseFileInventoryPlugin): if section in group_data and isinstance(group_data[section], string_types): group_data[section] = {group_data[section]: None} - if 'vars' in group_data: + if group_data.get('vars', False): for var in group_data['vars']: self.inventory.set_variable(group, var, group_data['vars'][var]) - if 'children' in group_data: + 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) - if 'hosts' in group_data: + 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)