# Buggy code
def get_lease(self):
    datastore, datacenter, resource_pool, network_mappings = self.get_objects()

    params = {
        "diskProvisioning": self.params["disk_provisioning"],
    }
    if self.params["name"]:
        params["entityName"] = self.params["name"]
    if network_mappings:
        params["networkMapping"] = network_mappings
    if self.params["deployment_option"]:
        params["deploymentOption"] = self.params["deployment_option"]
    if self.params["properties"]:
        params["propertyMapping"] = []
        for key, value in self.params["properties"].items():
            property_mapping = vim.KeyValue()
            property_mapping.key = key
            property_mapping.value = str(value) if isinstance(value, bool) else value
            params["propertyMapping"].append(property_mapping)

    if self.params["folder"]:
        folder = self.si.searchIndex.FindByInventoryPath(self.params["folder"])
        if not folder:
            self.module.fail_json(
                msg="Unable to find the specified folder %(folder)s" % self.params
            )
    else:
        folder = datacenter.vmFolder

    spec_params = vim.OvfManager.CreateImportSpecParams(**params)

    ovf_descriptor = self.get_ovf_descriptor()

    self.import_spec = self.si.ovfManager.CreateImportSpec(
        ovf_descriptor, resource_pool, datastore, spec_params
    )

    errors = [to_native(e.msg) for e in getattr(self.import_spec, "error", [])]
    if self.params["fail_on_spec_warnings"]:
        errors.extend(
            (to_native(w.msg) for w in getattr(self.import_spec, "warning", []))
        )
    if errors:
        self.module.fail_json(
            msg="Failure validating OVF import spec: %s" % ". ".join(errors)
        )

    for warning in getattr(self.import_spec, "warning", []):
        self.module.warn(
            "Problem validating OVF import spec: %s" % to_native(warning.msg)
        )

    if not self.params["allow_duplicates"]:
        name = self.import_spec.importSpec.configSpec.name
        match = find_vm_by_name(self.si, name, folder=folder)
        if match:
            self.module.exit_json(
                instance=gather_vm_facts(self.si, match), changed=False
            )

    if self.module.check_mode:
        self.module.exit_json(changed=True, instance={"hw_name": name})

    try:
        self.lease = resource_pool.ImportVApp(self.import_spec.importSpec, folder)
    except vmodl.fault.SystemError as e:
        self.module.fail_json(msg="Failed to start import: %s" % to_native(e.msg))

    while self.lease.state != vim.HttpNfcLease.State.ready:
        time.sleep(0.1)

    self.entity = self.lease.info.entity

    return self.lease, self.import_spec


# 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_lease(self):
    datastore, datacenter, resource_pool, network_mappings = self.get_objects()

    params = {
        "diskProvisioning": self.params["disk_provisioning"],
    }
    if self.params["name"]:
        params["entityName"] = self.params["name"]
    if network_mappings:
        params["networkMapping"] = network_mappings
    if self.params["deployment_option"]:
        params["deploymentOption"] = self.params["deployment_option"]
    if self.params["properties"]:
        params["propertyMapping"] = []
        for key, value in self.params["properties"].items():
            property_mapping = vim.KeyValue()
            property_mapping.key = key
            property_mapping.value = str(value) if isinstance(value, bool) else value
            params["propertyMapping"].append(property_mapping)

    if self.params["folder"]:
        folder = self.content.searchIndex.FindByInventoryPath(self.params["folder"])
        if not folder:
            self.module.fail_json(
                msg="Unable to find the specified folder %(folder)s" % self.params
            )
    else:
        folder = datacenter.vmFolder

    spec_params = vim.OvfManager.CreateImportSpecParams(**params)

    ovf_descriptor = self.get_ovf_descriptor()

    self.import_spec = self.content.ovfManager.CreateImportSpec(
        ovf_descriptor, resource_pool, datastore, spec_params
    )

    errors = [to_native(e.msg) for e in getattr(self.import_spec, "error", [])]
    if self.params["fail_on_spec_warnings"]:
        errors.extend(
            (to_native(w.msg) for w in getattr(self.import_spec, "warning", []))
        )
    if errors:
        self.module.fail_json(
            msg="Failure validating OVF import spec: %s" % ". ".join(errors)
        )

    for warning in getattr(self.import_spec, "warning", []):
        self.module.warn(
            "Problem validating OVF import spec: %s" % to_native(warning.msg)
        )

    if not self.params["allow_duplicates"]:
        name = self.import_spec.importSpec.configSpec.name
        match = find_vm_by_name(self.content, name, folder=folder)
        if match:
            self.module.exit_json(
                instance=gather_vm_facts(self.content, match), changed=False
            )

    if self.module.check_mode:
        self.module.exit_json(changed=True, instance={"hw_name": name})

    try:
        self.lease = resource_pool.ImportVApp(self.import_spec.importSpec, folder)
    except vmodl.fault.SystemError as e:
        self.module.fail_json(msg="Failed to start import: %s" % to_native(e.msg))

    while self.lease.state != vim.HttpNfcLease.State.ready:
        time.sleep(0.1)

    self.entity = self.lease.info.entity

    return self.lease, self.import_spec