From 70f6cdb8145a0c8c42217036b1c4636c9cbf5662 Mon Sep 17 00:00:00 2001 From: Abhijeet Kasurde Date: Wed, 6 Mar 2019 10:15:26 +0530 Subject: [PATCH] VMware: add cluster name in facts (#53056) Fixes: #45280 Signed-off-by: Abhijeet Kasurde --- lib/ansible/module_utils/vmware.py | 2 ++ lib/ansible/modules/cloud/vmware/vmware_host_facts.py | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/lib/ansible/module_utils/vmware.py b/lib/ansible/module_utils/vmware.py index 7559ea98d6..3d6a63b7e4 100644 --- a/lib/ansible/module_utils/vmware.py +++ b/lib/ansible/module_utils/vmware.py @@ -309,6 +309,8 @@ def gather_vm_facts(content, vm): try: host = vm.summary.runtime.host facts['hw_esxi_host'] = host.summary.config.name + facts['hw_cluster'] = host.parent.name if host.parent and isinstance(host.parent, vim.ClusterComputeResource) else None + except vim.fault.NoPermission: # User does not have read permission for the host system, # proceed without this value. This value does not contribute or hamper diff --git a/lib/ansible/modules/cloud/vmware/vmware_host_facts.py b/lib/ansible/modules/cloud/vmware/vmware_host_facts.py index f2bf63054e..22f37ac203 100644 --- a/lib/ansible/modules/cloud/vmware/vmware_host_facts.py +++ b/lib/ansible/modules/cloud/vmware/vmware_host_facts.py @@ -154,8 +154,15 @@ class VMwareHostFactManager(PyVmomi): ansible_facts.update(self.get_network_facts()) ansible_facts.update(self.get_system_facts()) ansible_facts.update(self.get_vsan_facts()) + ansible_facts.update(self.get_cluster_facts()) self.module.exit_json(changed=False, ansible_facts=ansible_facts) + def get_cluster_facts(self): + cluster_facts = {'cluster': None} + if self.host.parent and isinstance(self.host.parent, vim.ClusterComputeResource): + cluster_facts.update(cluster=self.host.parent.name) + return cluster_facts + def get_vsan_facts(self): config_mgr = self.host.configManager.vsanSystem if config_mgr is None: