mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
VMware: Add cluster fact in vmware_vm_facts (#44292)
This fix adds an additional fact about cluster in VM facts. Fixes: #44101 Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
This commit is contained in:
parent
66a8711ecb
commit
adf3ab5e72
2 changed files with 31 additions and 0 deletions
|
@ -20,6 +20,7 @@ module: vmware_vm_facts
|
|||
short_description: Return basic facts pertaining to a vSphere virtual machine guest
|
||||
description:
|
||||
- Return basic facts pertaining to a vSphere virtual machine guest.
|
||||
- Cluster name as fact is added in version 2.7.
|
||||
version_added: '2.0'
|
||||
author:
|
||||
- Joseph Callen (@jcpowermac)
|
||||
|
@ -84,6 +85,21 @@ virtual_machines:
|
|||
description: dictionary of virtual machines and their facts
|
||||
returned: success
|
||||
type: dict
|
||||
sample:
|
||||
{
|
||||
"ubuntu_t": {
|
||||
"cluster": null,
|
||||
"esxi_hostname": "10.76.33.226",
|
||||
"guest_fullname": "Ubuntu Linux (64-bit)",
|
||||
"ip_address": "",
|
||||
"mac_address": [
|
||||
"00:50:56:87:a5:9a"
|
||||
],
|
||||
"power_state": "poweredOff",
|
||||
"uuid": "4207072c-edd8-3bd5-64dc-903fd3a0db04",
|
||||
"vm_network": {}
|
||||
}
|
||||
}
|
||||
'''
|
||||
|
||||
try:
|
||||
|
@ -135,8 +151,14 @@ class VmwareVmFacts(PyVmomi):
|
|||
net_dict[device.macAddress]['ipv4'].append(ip_addr)
|
||||
|
||||
esxi_hostname = None
|
||||
esxi_parent = None
|
||||
if summary.runtime.host:
|
||||
esxi_hostname = summary.runtime.host.summary.config.name
|
||||
esxi_parent = summary.runtime.host.parent
|
||||
|
||||
cluster_name = None
|
||||
if esxi_parent and isinstance(esxi_parent, vim.ClusterComputeResource):
|
||||
cluster_name = summary.runtime.host.parent.name
|
||||
|
||||
virtual_machine = {
|
||||
summary.config.name: {
|
||||
|
@ -147,6 +169,7 @@ class VmwareVmFacts(PyVmomi):
|
|||
"uuid": summary.config.uuid,
|
||||
"vm_network": net_dict,
|
||||
"esxi_hostname": esxi_hostname,
|
||||
"cluster": cluster_name,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -50,5 +50,13 @@
|
|||
assert:
|
||||
that:
|
||||
- "{{ item | basename in vm_facts_0001['virtual_machines'].keys()}}"
|
||||
- "vm_facts_0001['virtual_machines'][item | basename]['cluster'] is defined"
|
||||
- "vm_facts_0001['virtual_machines'][item | basename]['esxi_hostname'] is defined"
|
||||
- "vm_facts_0001['virtual_machines'][item | basename]['guest_fullname'] is defined"
|
||||
- "vm_facts_0001['virtual_machines'][item | basename]['ip_address'] is defined"
|
||||
- "vm_facts_0001['virtual_machines'][item | basename]['mac_address'] is defined"
|
||||
- "vm_facts_0001['virtual_machines'][item | basename]['power_state'] is defined"
|
||||
- "vm_facts_0001['virtual_machines'][item | basename]['uuid'] is defined"
|
||||
- "vm_facts_0001['virtual_machines'][item | basename]['vm_network'] is defined"
|
||||
with_items:
|
||||
- "{{ host_info_result['json'] }}"
|
||||
|
|
Loading…
Reference in a new issue