From 8ce2ee0ebb55d146a5d729044bf190af40986cc5 Mon Sep 17 00:00:00 2001 From: Abhijeet Kasurde Date: Wed, 28 Mar 2018 00:27:17 +0530 Subject: [PATCH] VMware: Fix regression in get_all_host_objs (#36770) If user does not specify esxi_hostname then module fails to detect ESXi hostsystem from given configuration. This fixes the regression in get_all_host_objs API by getting first host managed object from list. Signed-off-by: Abhijeet Kasurde --- lib/ansible/modules/cloud/vmware/vmware_vmkernel.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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: