# Buggy code
def main():
    argument_spec = vmware_argument_spec()
    module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=False)

    if not HAS_PYVMOMI:
        module.fail_json(msg="pyvmomi is required for this module")

    content = connect_to_api(module)
    data = all_facts(content)
    module.exit_json(changed=False, ansible_facts=data)


# 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 main():
    argument_spec = vmware_argument_spec()
    module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True)

    vm_host_manager = VMwareHostFactManager(module)
    vm_host_manager.all_facts()