# Buggy code
def _load_inventory_file(self, path, loader):
    """
    helper function, which loads the file and gets the
    basename of the file without the extension
    """

    if loader.is_directory(path):
        data = dict()

        try:
            names = loader.list_directory(path)
        except os.error as err:
            raise AnsibleError(
                "This folder cannot be listed: %s: %s." % (path, err.strerror)
            )

        # evaluate files in a stable order rather than whatever
        # order the filesystem lists them.
        names.sort()

        # do not parse hidden files or dirs, e.g. .svn/
        paths = [os.path.join(path, name) for name in names if not name.startswith(".")]
        for p in paths:
            results = self._load_inventory_file(path=p, loader=loader)
            if results is not None:
                data = combine_vars(data, results)

    else:
        file_name, ext = os.path.splitext(path)
        data = None
        if not ext or ext not in C.YAML_FILENAME_EXTENSIONS:
            for test_ext in C.YAML_FILENAME_EXTENSIONS:
                new_path = path + test_ext
                if loader.path_exists(new_path):
                    data = loader.load_from_file(new_path)
                    break
        else:
            if loader.path_exists(path):
                data = loader.load_from_file(path)

    rval = AnsibleInventoryVarsData()
    rval.path = path
    if data is not None:
        rval.update(data)
    return rval


# Traceback (ValueError)
[dag@moria ansible.testing]$ ansible localhost -m setup -vvv
Using /home/dag/home-made/ansible.testing/ansible.cfg as config file
ERROR! Unexpected Exception: dictionary update sequence element #0 has length 1; 2 is required
the full traceback was:

Traceback (most recent call last):
File "/opt/ansible/default/bin/ansible", line 103, in <module>
exit_code = cli.run()
File "/opt/ansible/ansible-2.2.0.0/lib/ansible/cli/adhoc.py", line 131, in run
inventory = Inventory(loader=loader, variable_manager=variable_manager, host_list=self.options.inventory)
File "/opt/ansible/ansible-2.2.0.0/lib/ansible/inventory/__init__.py", line 97, in __init__
self.parse_inventory(host_list)
File "/opt/ansible/ansible-2.2.0.0/lib/ansible/inventory/__init__.py", line 164, in parse_inventory
group.vars = combine_vars(group.vars, self.get_group_variables(group.name))
File "/opt/ansible/ansible-2.2.0.0/lib/ansible/inventory/__init__.py", line 554, in get_group_variables
self._vars_per_group[groupname] = self._get_group_variables(groupname, vault_password=vault_password)
File "/opt/ansible/ansible-2.2.0.0/lib/ansible/inventory/__init__.py", line 572, in _get_group_variables
vars = combine_vars(vars, self.get_group_vars(group))
File "/opt/ansible/ansible-2.2.0.0/lib/ansible/inventory/__init__.py", line 774, in get_group_vars
return self._get_hostgroup_vars(host=None, group=group, new_pb_basedir=new_pb_basedir, return_results=return_results)
File "/opt/ansible/ansible-2.2.0.0/lib/ansible/inventory/__init__.py", line 835, in _get_hostgroup_vars
host_results = self._variable_manager.add_group_vars_file(base_path, self._loader)
File "/opt/ansible/ansible-2.2.0.0/lib/ansible/vars/__init__.py", line 615, in add_group_vars_file
data = self._load_inventory_file(path, loader)
File "/opt/ansible/ansible-2.2.0.0/lib/ansible/vars/__init__.py", line 573, in _load_inventory_file
rval.update(data)
ValueError: dictionary update sequence element #0 has length 1; 2 is required

# Fixed code
def _load_inventory_file(self, path, loader):
    """
    helper function, which loads the file and gets the
    basename of the file without the extension
    """

    if loader.is_directory(path):
        data = dict()

        try:
            names = loader.list_directory(path)
        except os.error as err:
            raise AnsibleError(
                "This folder cannot be listed: %s: %s." % (path, err.strerror)
            )

        # evaluate files in a stable order rather than whatever
        # order the filesystem lists them.
        names.sort()

        # do not parse hidden files or dirs, e.g. .svn/
        paths = [os.path.join(path, name) for name in names if not name.startswith(".")]
        for p in paths:
            results = self._load_inventory_file(path=p, loader=loader)
            if results is not None:
                data = combine_vars(data, results)

    else:
        file_name, ext = os.path.splitext(path)
        data = None
        if not ext or ext not in C.YAML_FILENAME_EXTENSIONS:
            for test_ext in C.YAML_FILENAME_EXTENSIONS:
                new_path = path + test_ext
                if loader.path_exists(new_path):
                    data = loader.load_from_file(new_path)
                    break
        else:
            if loader.path_exists(path):
                data = loader.load_from_file(path)

    rval = AnsibleInventoryVarsData()
    rval.path = path

    if data is not None:
        if not isinstance(data, dict):
            raise AnsibleError(
                "Problem parsing file '%s': line %d, column %d" % data.ansible_pos
            )
        else:
            rval.update(data)

    return rval