# Buggy code
def get_cpu_facts(host):
    facts = {
        "ansible_processor": host.summary.hardware.cpuModel,
        "ansible_processor_cores": host.summary.hardware.numCpuCores,
        "ansible_processor_count": host.summary.hardware.numCpuPkgs,
        "ansible_processor_vcpus": host.summary.hardware.numCpuThreads,
    }
    return facts


# Traceback (AttributeError)
Using module file /Users/phemmer/ansible-2.5/lib/python2.7/site-packages/ansible/modules/cloud/vmware/vmware_host_facts.py
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: phemmer
<127.0.0.1> EXEC /bin/sh -c 'echo ~ &amp;&amp; sleep 0'
<127.0.0.1> EXEC /bin/sh -c '( umask 77 &amp;&amp; mkdir -p "` echo /Users/phemmer/.ansible/tmp/ansible-tmp-1524622902.49-163489786567676 `" &amp;&amp; echo ansible-tmp-1524622902.49-163489786567676="` echo /Users/phemmer/.ansible/tmp/ansible-tmp-1524622902.49-163489786567676 `" ) &amp;&amp; sleep 0'
<127.0.0.1> PUT /Users/phemmer/.ansible/tmp/ansible-local-98035IJ9ktm/tmpfKLeea TO /Users/phemmer/.ansible/tmp/ansible-tmp-1524622902.49-163489786567676/vmware_host_facts.py
<127.0.0.1> EXEC /bin/sh -c 'chmod u+x /Users/phemmer/.ansible/tmp/ansible-tmp-1524622902.49-163489786567676/ /Users/phemmer/.ansible/tmp/ansible-tmp-1524622902.49-163489786567676/vmware_host_facts.py &amp;&amp; sleep 0'
<127.0.0.1> EXEC /bin/sh -c '/Users/phemmer/ansible-2.5/bin/python /Users/phemmer/.ansible/tmp/ansible-tmp-1524622902.49-163489786567676/vmware_host_facts.py &amp;&amp; sleep 0'
<127.0.0.1> EXEC /bin/sh -c 'rm -f -r /Users/phemmer/.ansible/tmp/ansible-tmp-1524622902.49-163489786567676/ > /dev/null 2>&amp;1 &amp;&amp; sleep 0'
The full traceback is:
Traceback (most recent call last):
File "/var/folders/xk/jhvsfjg14zqfgtwvm0kpsy61p_63g5/T/ansible_t2xrmq/ansible_module_vmware_host_facts.py", line 155, in <module>
main()
File "/var/folders/xk/jhvsfjg14zqfgtwvm0kpsy61p_63g5/T/ansible_t2xrmq/ansible_module_vmware_host_facts.py", line 150, in main
data = all_facts(content)
File "/var/folders/xk/jhvsfjg14zqfgtwvm0kpsy61p_63g5/T/ansible_t2xrmq/ansible_module_vmware_host_facts.py", line 133, in all_facts
ansible_facts.update(get_cpu_facts(host))
File "/var/folders/xk/jhvsfjg14zqfgtwvm0kpsy61p_63g5/T/ansible_t2xrmq/ansible_module_vmware_host_facts.py", line 60, in get_cpu_facts
'ansible_processor': host.summary.hardware.cpuModel,
AttributeError: 'NoneType' object has no attribute 'summary'

fatal: [localhost]: FAILED! => {
"changed": false,
"module_stderr": "Traceback (most recent call last):\n  File \"/var/folders/xk/jhvsfjg14zqfgtwvm0kpsy61p_63g5/T/ansible_t2xrmq/ansible_module_vmware_host_facts.py\", line 155, in <module>\n    main()\n  File \"/var/folders/xk/jhvsfjg14zqfgtwvm0kpsy61p_63g5/T/ansible_t2xrmq/ansible_module_vmware_host_facts.py\", line 150, in main\n    data = all_facts(content)\n  File \"/var/folders/xk/jhvsfjg14zqfgtwvm0kpsy61p_63g5/T/ansible_t2xrmq/ansible_module_vmware_host_facts.py\", line 133, in all_facts\n    ansible_facts.update(get_cpu_facts(host))\n  File \"/var/folders/xk/jhvsfjg14zqfgtwvm0kpsy61p_63g5/T/ansible_t2xrmq/ansible_module_vmware_host_facts.py\", line 60, in get_cpu_facts\n    'ansible_processor': host.summary.hardware.cpuModel,\nAttributeError: 'NoneType' object has no attribute 'summary'\n",
"module_stdout": "",
"msg": "MODULE FAILURE",
"rc": 1
}

# Fixed code
def get_cpu_facts(self):
    return {
        "ansible_processor": self.host.summary.hardware.cpuModel,
        "ansible_processor_cores": self.host.summary.hardware.numCpuCores,
        "ansible_processor_count": self.host.summary.hardware.numCpuPkgs,
        "ansible_processor_vcpus": self.host.summary.hardware.numCpuThreads,
    }