# Buggy code
def main():
    argument_spec = vmware_argument_spec()
    argument_spec.update(
        name=dict(type="str"),
        uuid=dict(type="str"),
        moid=dict(type="str"),
        folder=dict(type="str"),
        datacenter=dict(type="str"),
        esxi_hostname=dict(type="str"),
        cluster=dict(type="str"),
        local_path=dict(type="str"),
    )
    module = AnsibleModule(
        argument_spec=argument_spec, required_one_of=[["name", "uuid", "moid"]]
    )
    pyv = PyVmomiHelper(module)
    vm = pyv.get_vm()
    if not vm:
        vm_id = (
            module.params.get("uuid")
            or module.params.get("name")
            or module.params.get("moid")
        )
        module.fail_json(
            msg="Unable to find the specified virtual machine : %s" % vm_id
        )

    result = pyv.take_vm_screenshot()
    if result["failed"]:
        module.fail_json(**result)
    else:
        module.exit_json(**result)


# Traceback (AttributeError)
TASK [vmware_guest_screenshot : take screenshot of virtual machine's console and download to local] **********************************************
task path: /home/goneri/.ansible/test/tmp/vmware_guest_screenshot-yyx29421-ÅÑŚÌβŁÈ/test/integration/targets/vmware_guest_screenshot/tasks/main.yml:38
<testhost> ESTABLISH LOCAL CONNECTION FOR USER: goneri
<testhost> EXEC /bin/sh -c 'echo ~goneri &amp;&amp; sleep 0'
<testhost> EXEC /bin/sh -c '( umask 77 &amp;&amp; mkdir -p "` echo /home/goneri/.ansible/tmp/ansible-tmp-1565778524.0166469-178908954277069 `" &amp;&amp; echo ansible-tmp-1565778524.0166469-178908954277069="` echo /home/goneri/.ansible/tmp/ansible-tmp-1565778524.0166469-178908954277069 `" ) &amp;&amp; sleep 0'
Using module file /home/goneri/git_repos/ansible_projects/c/lib/ansible/modules/cloud/vmware/vmware_guest_screenshot.py
<testhost> PUT /home/goneri/.ansible/tmp/ansible-local-3806uqeztqz4/tmplgf85opc TO /home/goneri/.ansible/tmp/ansible-tmp-1565778524.0166469-178908954277069/AnsiballZ_vmware_guest_screenshot.py
<testhost> EXEC /bin/sh -c 'chmod u+x /home/goneri/.ansible/tmp/ansible-tmp-1565778524.0166469-178908954277069/ /home/goneri/.ansible/tmp/ansible-tmp-1565778524.0166469-178908954277069/AnsiballZ_vmware_guest_screenshot.py &amp;&amp; sleep 0'
<testhost> EXEC /bin/sh -c 'ESXI1_HOSTNAME=root ESXI1_PASSWORD='"'"'!234AaAa56'"'"' ESXI1_USERNAME=esxi1.test ESXI2_HOSTNAME=root ESXI2_PASSWORD='"'"'!234AaAa56'"'"' ESXI2_USERNAME=esxi2.test VCENTER_HOSTNAME=vcenter.test VCENTER_PASSWORD='"'"'!234AaAa56'"'"' VCENTER_USERNAME=administrator@vsphere.local VMWARE_PROXY_HOST='"'"''"'"' VMWARE_PROXY_PORT=0 VMWARE_VALIDATE_CERTS=False /home/goneri/git_repos/ansible_projects/c/.virtualenv/py37/bin/python /home/goneri/.ansible/tmp/ansible-tmp-1565778524.0166469-178908954277069/AnsiballZ_vmware_guest_screenshot.py &amp;&amp; sleep 0'
<testhost> EXEC /bin/sh -c 'rm -f -r /home/goneri/.ansible/tmp/ansible-tmp-1565778524.0166469-178908954277069/ > /dev/null 2>&amp;1 &amp;&amp; sleep 0'
The full traceback is:
Traceback (most recent call last):
File "/home/goneri/.ansible/tmp/ansible-tmp-1565778524.0166469-178908954277069/AnsiballZ_vmware_guest_screenshot.py", line 139, in <module>
_ansiballz_main()
File "/home/goneri/.ansible/tmp/ansible-tmp-1565778524.0166469-178908954277069/AnsiballZ_vmware_guest_screenshot.py", line 131, in _ansiballz_main
invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
File "/home/goneri/.ansible/tmp/ansible-tmp-1565778524.0166469-178908954277069/AnsiballZ_vmware_guest_screenshot.py", line 65, in invoke_module
spec.loader.exec_module(module)
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/tmp/ansible_vmware_guest_screenshot_payload_ka1817jv/__main__.py", line 293, in <module>
File "/tmp/ansible_vmware_guest_screenshot_payload_ka1817jv/__main__.py", line 285, in main
File "/tmp/ansible_vmware_guest_screenshot_payload_ka1817jv/__main__.py", line 251, in take_vm_screenshot
File "/tmp/ansible_vmware_guest_screenshot_payload_ka1817jv/__main__.py", line 169, in generate_http_access_url
AttributeError: 'PyVmomiHelper' object has no attribute 'get_parent_datacenter'

fatal: [testhost]: FAILED! => {
"changed": false,
"module_stderr": "Traceback (most recent call last):\n  File \"/home/goneri/.ansible/tmp/ansible-tmp-1565778524.0166469-178908954277069/AnsiballZ_vmware_guest_screenshot.py\", line 139, in <module>\n    _ansiballz_main()\n  File \"/home/goneri/.ansible/tmp/ansible-tmp-1565778524.0166469-178908954277069/AnsiballZ_vmware_guest_screenshot.py\", line 131, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \"/home/goneri/.ansible/tmp/ansible-tmp-1565778524.0166469-178908954277069/AnsiballZ_vmware_guest_screenshot.py\", line 65, in invoke_module\n    spec.loader.exec_module(module)\n  File \"<frozen importlib._bootstrap_external>\", line 728, in exec_module\n  File \"<frozen importlib._bootstrap>\", line 219, in _call_with_frames_removed\n  File \"/tmp/ansible_vmware_guest_screenshot_payload_ka1817jv/__main__.py\", line 293, in <module>\n  File \"/tmp/ansible_vmware_guest_screenshot_payload_ka1817jv/__main__.py\", line 285, in main\n  File \"/tmp/ansible_vmware_guest_screenshot_payload_ka1817jv/__main__.py\", line 251, in take_vm_screenshot\n  File \"/tmp/ansible_vmware_guest_screenshot_payload_ka1817jv/__main__.py\", line 169, in generate_http_access_url\nAttributeError: 'PyVmomiHelper' object has no attribute 'get_parent_datacenter'\n",
"module_stdout": "",
"msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
"rc": 1
}

# Fixed code
def main():
    argument_spec = vmware_argument_spec()
    argument_spec.update(
        name=dict(type="str"),
        uuid=dict(type="str"),
        moid=dict(type="str"),
        folder=dict(type="str"),
        datacenter=dict(type="str"),
        esxi_hostname=dict(type="str"),
        cluster=dict(type="str"),
        local_path=dict(type="path"),
    )
    module = AnsibleModule(
        argument_spec=argument_spec, required_one_of=[["name", "uuid", "moid"]]
    )
    pyv = PyVmomiHelper(module)
    vm = pyv.get_vm()
    if not vm:
        vm_id = (
            module.params.get("uuid")
            or module.params.get("name")
            or module.params.get("moid")
        )
        module.fail_json(
            msg="Unable to find the specified virtual machine : %s" % vm_id
        )

    result = pyv.take_vm_screenshot()
    if result["failed"]:
        module.fail_json(**result)
    else:
        module.exit_json(**result)