# Buggy code
def parse(self, inventory, loader, path, cache=True):
    """
    Parses the inventory file
    """

    if not HAS_REQUESTS:
        raise AnsibleParserError(
            'Please install "requests" Python module as this is required'
            " for VMware Guest dynamic inventory plugin."
        )
    elif not HAS_PYVMOMI:
        raise AnsibleParserError(
            'Please install "PyVmomi" Python module as this is required'
            " for VMware Guest dynamic inventory plugin."
        )
    if HAS_REQUESTS:
        # Pyvmomi 5.5 and onwards requires requests 2.3
        # https://github.com/vmware/pyvmomi/blob/master/requirements.txt
        required_version = (2, 3)
        requests_version = requests.__version__.split(".")[:2]
        try:
            requests_major_minor = tuple(map(int, requests_version))
        except ValueError:
            raise AnsibleParserError("Failed to parse 'requests' library version.")

        if requests_major_minor < required_version:
            raise AnsibleParserError(
                "'requests' library version should"
                " be >= %s, found: %s."
                % (".".join([str(w) for w in required_version]), requests.__version__)
            )

    super(InventoryModule, self).parse(inventory, loader, path, cache=cache)

    cache_key = self.get_cache_key(path)

    config_data = self._read_config_data(path)

    source_data = None
    if cache:
        cache = self.get_option("cache")

    update_cache = False
    if cache:
        try:
            source_data = self.cache.get(cache_key)
        except KeyError:
            update_cache = True

    # set _options from config data
    self._consume_options(config_data)

    self._set_credentials()
    self.content = self._login()
    if self.with_tags:
        self.rest_content = self._login_vapi()

    using_current_cache = cache and not update_cache
    cacheable_results = self._populate_from_source(source_data, using_current_cache)

    if update_cache:
        self.cache.set(cache_key, cacheable_results)


# Traceback (RepresenterError)
ansible-inventory --list --yaml -i inventory.vmware.yml -vvvv
ansible-inventory 2.7.7
config file = /mnt/ansible/ansible.cfg
configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
ansible python module location = /usr/local/lib/python2.7/site-packages/ansible
executable location = /usr/local/bin/ansible-inventory
python version = 2.7.15 (default, Feb  6 2019, 12:35:55) [GCC 6.3.0 20170516]
Using /mnt/ansible/ansible.cfg as config file
setting up inventory plugins
/mnt/ansible/inventory.vmware.yml did not meet host_list requirements, check plugin documentation if this is unexpected
/mnt/ansible/inventory.vmware.yml did not meet script requirements, check plugin documentation if this is unexpected
Parsed /mnt/ansible/inventory.vmware.yml inventory source with auto plugin
ERROR! Unexpected Exception, this is probably a bug: cannot represent an object: (vim.CustomFieldsManager.Value) []
the full traceback was:

Traceback (most recent call last):
File "/usr/local/bin/ansible-inventory", line 118, in <module>
exit_code = cli.run()
File "/usr/local/lib/python2.7/site-packages/ansible/cli/inventory.py", line 181, in run
results = self.dump(results)
File "/usr/local/lib/python2.7/site-packages/ansible/cli/inventory.py", line 195, in dump
results = yaml.dump(stuff, Dumper=AnsibleDumper, default_flow_style=False)
File "/usr/local/lib/python2.7/site-packages/yaml/__init__.py", line 202, in dump
return dump_all([data], stream, Dumper=Dumper, **kwds)
File "/usr/local/lib/python2.7/site-packages/yaml/__init__.py", line 190, in dump_all
dumper.represent(data)
File "/usr/local/lib/python2.7/site-packages/yaml/representer.py", line 28, in represent
node = self.represent_data(data)
File "/usr/local/lib/python2.7/site-packages/yaml/representer.py", line 57, in represent_data
node = self.yaml_representers[data_types[0]](self, data)
File "/usr/local/lib/python2.7/site-packages/yaml/representer.py", line 225, in represent_dict
return self.represent_mapping(u'tag:yaml.org,2002:map', data)
File "/usr/local/lib/python2.7/site-packages/yaml/representer.py", line 123, in represent_mapping
node_value = self.represent_data(item_value)
File "/usr/local/lib/python2.7/site-packages/yaml/representer.py", line 57, in represent_data
node = self.yaml_representers[data_types[0]](self, data)
File "/usr/local/lib/python2.7/site-packages/yaml/representer.py", line 225, in represent_dict
return self.represent_mapping(u'tag:yaml.org,2002:map', data)
File "/usr/local/lib/python2.7/site-packages/yaml/representer.py", line 123, in represent_mapping
node_value = self.represent_data(item_value)
File "/usr/local/lib/python2.7/site-packages/yaml/representer.py", line 57, in represent_data
node = self.yaml_representers[data_types[0]](self, data)
File "/usr/local/lib/python2.7/site-packages/yaml/representer.py", line 225, in represent_dict
return self.represent_mapping(u'tag:yaml.org,2002:map', data)
File "/usr/local/lib/python2.7/site-packages/yaml/representer.py", line 123, in represent_mapping
node_value = self.represent_data(item_value)
File "/usr/local/lib/python2.7/site-packages/yaml/representer.py", line 57, in represent_data
node = self.yaml_representers[data_types[0]](self, data)
File "/usr/local/lib/python2.7/site-packages/yaml/representer.py", line 225, in represent_dict
return self.represent_mapping(u'tag:yaml.org,2002:map', data)
File "/usr/local/lib/python2.7/site-packages/yaml/representer.py", line 123, in represent_mapping
node_value = self.represent_data(item_value)
File "/usr/local/lib/python2.7/site-packages/yaml/representer.py", line 57, in represent_data
node = self.yaml_representers[data_types[0]](self, data)
File "/usr/local/lib/python2.7/site-packages/yaml/representer.py", line 225, in represent_dict
return self.represent_mapping(u'tag:yaml.org,2002:map', data)
File "/usr/local/lib/python2.7/site-packages/yaml/representer.py", line 123, in represent_mapping
node_value = self.represent_data(item_value)
File "/usr/local/lib/python2.7/site-packages/yaml/representer.py", line 57, in represent_data
node = self.yaml_representers[data_types[0]](self, data)
File "/usr/local/lib/python2.7/site-packages/yaml/representer.py", line 225, in represent_dict
return self.represent_mapping(u'tag:yaml.org,2002:map', data)
File "/usr/local/lib/python2.7/site-packages/yaml/representer.py", line 123, in represent_mapping
node_value = self.represent_data(item_value)
File "/usr/local/lib/python2.7/site-packages/yaml/representer.py", line 67, in represent_data
node = self.yaml_representers[None](self, data)
File "/usr/local/lib/python2.7/site-packages/yaml/representer.py", line 249, in represent_undefined
raise RepresenterError("cannot represent an object: %s" % data)
RepresenterError: cannot represent an object: (vim.CustomFieldsManager.Value) []

# Fixed code
def parse(self, inventory, loader, path, cache=True):
    """
    Parses the inventory file
    """
    super(InventoryModule, self).parse(inventory, loader, path, cache=cache)

    cache_key = self.get_cache_key(path)

    config_data = self._read_config_data(path)

    # set _options from config data
    self._consume_options(config_data)

    self.pyv = BaseVMwareInventory(
        hostname=self.get_option("hostname"),
        username=self.get_option("username"),
        password=self.get_option("password"),
        port=self.get_option("port"),
        with_tags=self.get_option("with_tags"),
        validate_certs=self.get_option("validate_certs"),
    )

    self.pyv.do_login()

    self.pyv.check_requirements()

    source_data = None
    if cache:
        cache = self.get_option("cache")

    update_cache = False
    if cache:
        try:
            source_data = self.cache.get(cache_key)
        except KeyError:
            update_cache = True

    using_current_cache = cache and not update_cache
    cacheable_results = self._populate_from_source(source_data, using_current_cache)

    if update_cache:
        self.cache.set(cache_key, cacheable_results)