# Buggy code
def main():
    module = AnsibleModule(
        argument_spec=dict(
            hostname=dict(type="str", default=os.environ.get("VMWARE_HOST")),
            username=dict(type="str", default=os.environ.get("VMWARE_USER")),
            password=dict(
                type="str", no_log=True, default=os.environ.get("VMWARE_PASSWORD")
            ),
            validate_certs=dict(required=False, type="bool", default=True),
            name=dict(required=True, type="str"),
            name_match=dict(required=False, type="str", default="first"),
            uuid=dict(required=False, type="str"),
            folder=dict(required=False, type="str", default="/vm"),
            datacenter=dict(required=True, type="str"),
        ),
        required_together=[("name", "folder")],
    )

    # FindByInventoryPath() does not require an absolute path
    # so we should leave the input folder path unmodified
    module.params["folder"] = module.params["folder"].rstrip("/")

    pyv = PyVmomiHelper(module)
    # Check if the VM exists before continuing
    vm = pyv.getvm(
        name=module.params["name"],
        folder=module.params["folder"],
        uuid=module.params["uuid"],
    )

    # VM already exists
    if vm:
        try:
            module.exit_json(instance=pyv.gather_facts(vm))
        except Exception as exc:
            module.fail_json(msg="Fact gather failed with exception %s" % to_text(exc))
    else:
        module.fail_json(
            msg="Unable to gather facts for non-existing VM %(name)s" % module.params
        )


# Traceback (TypeError)
The full traceback is:
Traceback (most recent call last):
File "/tmp/ansible_xTG64q/ansible_module_vmware_guest_facts.py", line 236, in <module>
main()
File "/tmp/ansible_xTG64q/ansible_module_vmware_guest_facts.py", line 223, in main
uuid=module.params['uuid'])
File "/tmp/ansible_xTG64q/ansible_module_vmware_guest_facts.py", line 128, in getvm
vm = find_vm_by_id(self.content, vm_id=uuid, vm_id_type="uuid")
File "/tmp/ansible_xTG64q/ansible_modlib.zip/ansible/module_utils/vmware.py", line 182, in find_vm_by_id
File "/usr/lib/python2.7/site-packages/pyVmomi/VmomiSupport.py", line 580, in <lambda>
self.f(*(self.args + (obj,) + args), **kwargs)
File "/usr/lib/python2.7/site-packages/pyVmomi/VmomiSupport.py", line 385, in _InvokeMethod
list(map(CheckField, info.params, args))
File "/usr/lib/python2.7/site-packages/pyVmomi/VmomiSupport.py", line 915, in CheckField
raise TypeError('Required field "%s" not provided (not @optional)' % info.name)
TypeError: Required field "uuid" not provided (not @optional)

# Fixed code
def main():
    module = AnsibleModule(
        argument_spec=dict(
            hostname=dict(type="str", default=os.environ.get("VMWARE_HOST")),
            username=dict(type="str", default=os.environ.get("VMWARE_USER")),
            password=dict(
                type="str", no_log=True, default=os.environ.get("VMWARE_PASSWORD")
            ),
            validate_certs=dict(required=False, type="bool", default=True),
            name=dict(required=False, type="str"),
            name_match=dict(required=False, type="str", default="first"),
            uuid=dict(required=False, type="str"),
            folder=dict(required=False, type="str", default="/vm"),
            datacenter=dict(required=True, type="str"),
        ),
        required_together=[("name", "folder")],
        required_one_of=[["name", "uuid"]],
    )

    # FindByInventoryPath() does not require an absolute path
    # so we should leave the input folder path unmodified
    module.params["folder"] = module.params["folder"].rstrip("/")

    pyv = PyVmomiHelper(module)
    # Check if the VM exists before continuing
    vm = pyv.getvm(
        name=module.params["name"],
        folder=module.params["folder"],
        uuid=module.params["uuid"],
    )

    # VM already exists
    if vm:
        try:
            module.exit_json(instance=pyv.gather_facts(vm))
        except Exception as exc:
            module.fail_json(msg="Fact gather failed with exception %s" % to_text(exc))
    else:
        msg = "Unable to gather facts for non-existing VM "
        if module.params["name"]:
            msg += "%(name)s" % module.params
        elif module.params["uuid"]:
            msg += "%(uuid)s" % module.params
        module.fail_json(msg=msg)