# Buggy code
def get_objects(self):
    self.datacenter = self.find_datacenter_by_name(self.params["datacenter"])
    if not self.datacenter:
        self.module.fail_json(msg="%(datacenter)s could not be located" % self.params)

    self.datastore = None
    datastore_cluster_obj = self.find_datastore_cluster_by_name(
        self.params["datastore"]
    )
    if datastore_cluster_obj:
        datastore = None
        datastore_freespace = 0
        for ds in datastore_cluster_obj.childEntity:
            if (
                isinstance(ds, vim.Datastore)
                and ds.summary.freeSpace > datastore_freespace
            ):
                # If datastore field is provided, filter destination datastores
                if ds.summary.maintenanceMode != "normal" or not ds.summary.accessible:
                    continue
                datastore = ds
                datastore_freespace = ds.summary.freeSpace
        if datastore:
            self.datastore = datastore
    else:
        self.datastore = self.find_datastore_by_name(self.params["datastore"])

    if not self.datastore:
        self.module.fail_json(msg="%(datastore)s could not be located" % self.params)

    if self.params["cluster"]:
        resource_pools = []
        cluster = self.find_cluster_by_name(
            self.params["cluster"], datacenter_name=self.datacenter
        )
        if cluster is None:
            self.module.fail_json(
                msg="Unable to find cluster '%(cluster)s'" % self.params
            )
        self.resource_pool = self.find_resource_pool_by_cluster(
            self.params["resource_pool"], cluster=cluster
        )
    else:
        self.resource_pool = self.find_resource_pool_by_name(
            self.params["resource_pool"]
        )

    if not self.resource_pool:
        self.module.fail_json(
            msg="%(resource_pool)s could not be located" % self.params
        )

    for key, value in self.params["networks"].items():
        network = find_network_by_name(self.si, value)
        if not network:
            self.module.fail_json(msg="%(network)s could not be located" % self.params)
        network_mapping = vim.OvfManager.NetworkMapping()
        network_mapping.name = key
        network_mapping.network = network
        self.network_mappings.append(network_mapping)

    return self.datastore, self.datacenter, self.resource_pool, self.network_mappings


# Traceback (AttributeError)
The full traceback is:
Traceback (most recent call last):
File "/home/qiz/.ansible/tmp/ansible-tmp-1564076387.99-37546435245957/AnsiballZ_vmware_deploy_ovf.py", line 125, in <module>
_ansiballz_main()
File "/home/qiz/.ansible/tmp/ansible-tmp-1564076387.99-37546435245957/AnsiballZ_vmware_deploy_ovf.py", line 117, in _ansiballz_main
invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
File "/home/qiz/.ansible/tmp/ansible-tmp-1564076387.99-37546435245957/AnsiballZ_vmware_deploy_ovf.py", line 54, in invoke_module
imp.load_module('__main__', mod, module, MOD_DESC)
File "/tmp/ansible_vmware_deploy_ovf_payload_MVOaC0/__main__.py", line 704, in <module>
File "/tmp/ansible_vmware_deploy_ovf_payload_MVOaC0/__main__.py", line 696, in main
File "/tmp/ansible_vmware_deploy_ovf_payload_MVOaC0/__main__.py", line 484, in upload
File "/tmp/ansible_vmware_deploy_ovf_payload_MVOaC0/__main__.py", line 389, in get_lease
File "/tmp/ansible_vmware_deploy_ovf_payload_MVOaC0/__main__.py", line 359, in get_objects
File "/tmp/ansible_vmware_deploy_ovf_payload_MVOaC0/ansible_vmware_deploy_ovf_payload.zip/ansible/module_utils/vmware.py", line 186, in find_network_by_name
File "/tmp/ansible_vmware_deploy_ovf_payload_MVOaC0/ansible_vmware_deploy_ovf_payload.zip/ansible/module_utils/vmware.py", line 132, in find_object_by_name
File "/tmp/ansible_vmware_deploy_ovf_payload_MVOaC0/ansible_vmware_deploy_ovf_payload.zip/ansible/module_utils/vmware.py", line 565, in get_all_objs
AttributeError: 'vim.ServiceInstance' object has no attribute 'rootFolder'

fatal: [localhost -> localhost]: FAILED! => {
"changed": false,
"module_stderr": "Traceback (most recent call last):\n  File \"/home/qiz/.ansible/tmp/ansible-tmp-1564076387.99-37546435245957/AnsiballZ_vmware_deploy_ovf.py\", line 125, in <module>\n    _ansiballz_main()\n  File \"/home/qiz/.ansible/tmp/ansible-tmp-1564076387.99-37546435245957/AnsiballZ_vmware_deploy_ovf.py\", line 117, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \"/home/qiz/.ansible/tmp/ansible-tmp-1564076387.99-37546435245957/AnsiballZ_vmware_deploy_ovf.py\", line 54, in invoke_module\n    imp.load_module('__main__', mod, module, MOD_DESC)\n  File \"/tmp/ansible_vmware_deploy_ovf_payload_MVOaC0/__main__.py\", line 704, in <module>\n  File \"/tmp/ansible_vmware_deploy_ovf_payload_MVOaC0/__main__.py\", line 696, in main\n  File \"/tmp/ansible_vmware_deploy_ovf_payload_MVOaC0/__main__.py\", line 484, in upload\n  File \"/tmp/ansible_vmware_deploy_ovf_payload_MVOaC0/__main__.py\", line 389, in get_lease\n  File \"/tmp/ansible_vmware_deploy_ovf_payload_MVOaC0/__main__.py\", line 359, in get_objects\n  File \"/tmp/ansible_vmware_deploy_ovf_payload_MVOaC0/ansible_vmware_deploy_ovf_payload.zip/ansible/module_utils/vmware.py\", line 186, in find_network_by_name\n  File \"/tmp/ansible_vmware_deploy_ovf_payload_MVOaC0/ansible_vmware_deploy_ovf_payload.zip/ansible/module_utils/vmware.py\", line 132, in find_object_by_name\n  File \"/tmp/ansible_vmware_deploy_ovf_payload_MVOaC0/ansible_vmware_deploy_ovf_payload.zip/ansible/module_utils/vmware.py\", line 565, in get_all_objs\nAttributeError: 'vim.ServiceInstance' object has no attribute 'rootFolder'\n",
"module_stdout": "",
"msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
"rc": 1
}

# Fixed code
def get_objects(self):
    self.datacenter = self.find_datacenter_by_name(self.params["datacenter"])
    if not self.datacenter:
        self.module.fail_json(msg="%(datacenter)s could not be located" % self.params)

    self.datastore = None
    datastore_cluster_obj = self.find_datastore_cluster_by_name(
        self.params["datastore"]
    )
    if datastore_cluster_obj:
        datastore = None
        datastore_freespace = 0
        for ds in datastore_cluster_obj.childEntity:
            if (
                isinstance(ds, vim.Datastore)
                and ds.summary.freeSpace > datastore_freespace
            ):
                # If datastore field is provided, filter destination datastores
                if ds.summary.maintenanceMode != "normal" or not ds.summary.accessible:
                    continue
                datastore = ds
                datastore_freespace = ds.summary.freeSpace
        if datastore:
            self.datastore = datastore
    else:
        self.datastore = self.find_datastore_by_name(self.params["datastore"])

    if not self.datastore:
        self.module.fail_json(msg="%(datastore)s could not be located" % self.params)

    if self.params["cluster"]:
        resource_pools = []
        cluster = self.find_cluster_by_name(
            self.params["cluster"], datacenter_name=self.datacenter
        )
        if cluster is None:
            self.module.fail_json(
                msg="Unable to find cluster '%(cluster)s'" % self.params
            )
        self.resource_pool = self.find_resource_pool_by_cluster(
            self.params["resource_pool"], cluster=cluster
        )
    else:
        self.resource_pool = self.find_resource_pool_by_name(
            self.params["resource_pool"]
        )

    if not self.resource_pool:
        self.module.fail_json(
            msg="%(resource_pool)s could not be located" % self.params
        )

    for key, value in self.params["networks"].items():
        network = find_network_by_name(self.content, value)
        if not network:
            self.module.fail_json(msg="%(network)s could not be located" % self.params)
        network_mapping = vim.OvfManager.NetworkMapping()
        network_mapping.name = key
        network_mapping.network = network
        self.network_mappings.append(network_mapping)

    return self.datastore, self.datacenter, self.resource_pool, self.network_mappings