1
0
Fork 0
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:
Abhijeet Kasurde 2018-08-18 18:51:37 +05:30 committed by GitHub
parent 66a8711ecb
commit adf3ab5e72
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 0 deletions

View file

@ -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,
}
}

View file

@ -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'] }}"