# Buggy code
def get_system_facts(host):
    sn = "NA"
    for info in host.hardware.systemInfo.otherIdentifyingInfo:
        if info.identifierType.key == "ServiceTag":
            sn = info.identifierValue
    facts = {
        "ansible_distribution": host.config.product.name,
        "ansible_distribution_version": host.config.product.version,
        "ansible_distribution_build": host.config.product.build,
        "ansible_os_type": host.config.product.osType,
        "ansible_system_vendor": host.hardware.systemInfo.vendor,
        "ansible_hostname": host.summary.config.name,
        "ansible_product_name": host.hardware.systemInfo.model,
        "ansible_product_serial": sn,
        "ansible_bios_date": host.hardware.biosInfo.releaseDate,
        "ansible_bios_version": host.hardware.biosInfo.biosVersion,
    }
    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_system_facts(self):
    sn = "NA"
    for info in self.host.hardware.systemInfo.otherIdentifyingInfo:
        if info.identifierType.key == "ServiceTag":
            sn = info.identifierValue
    facts = {
        "ansible_distribution": self.host.config.product.name,
        "ansible_distribution_version": self.host.config.product.version,
        "ansible_distribution_build": self.host.config.product.build,
        "ansible_os_type": self.host.config.product.osType,
        "ansible_system_vendor": self.host.hardware.systemInfo.vendor,
        "ansible_hostname": self.host.summary.config.name,
        "ansible_product_name": self.host.hardware.systemInfo.model,
        "ansible_product_serial": sn,
        "ansible_bios_date": self.host.hardware.biosInfo.releaseDate,
        "ansible_bios_version": self.host.hardware.biosInfo.biosVersion,
    }
    return facts