handle groups correctly when they are 'null' (#41698)

* handle groups correctly when they are 'null'

 - even if defined as mapping but having no keys, objects shoudl still be processed correctly
 - also add ansilbe_verbosity to vars not to display in ansible-inventory

fixes #41692

(cherry picked from commit 05a49d6eb6)
This commit is contained in:
Brian Coca 2018-06-20 11:26:46 -04:00 committed by Matt Clay
parent d95cf17dd4
commit 4930710af2
3 changed files with 29 additions and 24 deletions

View file

@ -0,0 +1,2 @@
bugfixes:
- correctly handle yaml inventory files when entries are null dicts https://github.com/ansible/ansible/issues/41692

View file

@ -42,6 +42,7 @@ INTERNAL_VARS = frozenset(['ansible_diff_mode',
'ansible_playbook_python',
'ansible_run_tags',
'ansible_skip_tags',
'ansible_verbosity',
'ansible_version',
'inventory_dir',
'inventory_file',

View file

@ -59,6 +59,7 @@ all: # keys must be unique, i.e. only one 'hosts' per group
'''
import os
from collections import MutableMapping
from ansible.errors import AnsibleParserError
@ -112,10 +113,11 @@ class InventoryModule(BaseFileInventoryPlugin):
def _parse_group(self, group, group_data):
if isinstance(group_data, MutableMapping):
if isinstance(group_data, (MutableMapping, type(None))):
self.inventory.add_group(group)
if group_data is not None:
# make sure they are dicts
for section in ['vars', 'children', 'hosts']:
if section in group_data:
@ -123,7 +125,7 @@ class InventoryModule(BaseFileInventoryPlugin):
if isinstance(group_data[section], string_types):
group_data[section] = {group_data[section]: None}
if not isinstance(group_data[section], MutableMapping):
if not isinstance(group_data[section], (MutableMapping, type(None))):
raise AnsibleParserError('Invalid "%s" entry for "%s" group, requires a dictionary, found "%s" instead.' %
(section, group, type(group_data[section])))