diff --git a/lib/ansible/modules/cloud/vmware/vmware_vmkernel.py b/lib/ansible/modules/cloud/vmware/vmware_vmkernel.py index 20d7cd697f..4bc0b3a3a4 100644 --- a/lib/ansible/modules/cloud/vmware/vmware_vmkernel.py +++ b/lib/ansible/modules/cloud/vmware/vmware_vmkernel.py @@ -188,7 +188,13 @@ class PyVmomiHelper(PyVmomi): self.vlan_id = self.params['vlan_id'] self.esxi_host_name = self.params['esxi_hostname'] - self.esxi_host_obj = self.get_all_host_objs(esxi_host_name=self.esxi_host_name)[0] + + hosts = self.get_all_host_objs(esxi_host_name=self.esxi_host_name) + if hosts: + self.esxi_host_obj = hosts[0] + else: + self.module.fail_json("Failed to get details of ESXi server." + " Please specify esxi_hostname.") self.port_group_obj = self.get_port_group_by_name(host_system=self.esxi_host_obj, portgroup_name=self.port_group_name) if not self.port_group_obj: