# Buggy code
def get_all_host_objs(self, cluster_name=None, esxi_host_name=None):
    """
    Function to get all host system managed object

    Args:
        cluster_name: Name of Cluster
        esxi_host_name: Name of ESXi server

    Returns: A list of all host system managed objects, else empty list

    """
    host_obj_list = []
    if not self.is_vcenter():
        hosts = get_all_objs(self.content, [vim.HostSystem]).keys()
        if hosts:
            host_obj_list.append(hosts[0])
    else:
        if cluster_name:
            cluster_obj = self.find_cluster_by_name(cluster_name=cluster_name)
            if cluster_obj:
                host_obj_list = [host for host in cluster_obj.host]
            else:
                self.module.fail_json(
                    changed=False, msg="Cluster '%s' not found" % cluster_name
                )
        elif esxi_host_name:
            if isinstance(esxi_host_name, str):
                esxi_host_name = [esxi_host_name]

            for host in esxi_host_name:
                esxi_host_obj = self.find_hostsystem_by_name(host_name=host)
                if esxi_host_obj:
                    host_obj_list = [esxi_host_obj]
                else:
                    self.module.fail_json(
                        changed=False, msg="ESXi '%s' not found" % host
                    )

    return host_obj_list


# 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_all_host_objs(self, cluster_name=None, esxi_host_name=None):
    """
    Function to get all host system managed object

    Args:
        cluster_name: Name of Cluster
        esxi_host_name: Name of ESXi server

    Returns: A list of all host system managed objects, else empty list

    """
    host_obj_list = []
    if not self.is_vcenter():
        hosts = get_all_objs(self.content, [vim.HostSystem]).keys()
        if hosts:
            host_obj_list.append(list(hosts)[0])
    else:
        if cluster_name:
            cluster_obj = self.find_cluster_by_name(cluster_name=cluster_name)
            if cluster_obj:
                host_obj_list = [host for host in cluster_obj.host]
            else:
                self.module.fail_json(
                    changed=False, msg="Cluster '%s' not found" % cluster_name
                )
        elif esxi_host_name:
            if isinstance(esxi_host_name, str):
                esxi_host_name = [esxi_host_name]

            for host in esxi_host_name:
                esxi_host_obj = self.find_hostsystem_by_name(host_name=host)
                if esxi_host_obj:
                    host_obj_list = [esxi_host_obj]
                else:
                    self.module.fail_json(
                        changed=False, msg="ESXi '%s' not found" % host
                    )

    return host_obj_list