Repository: ansible-collections/community.vmware

Issue:
community.vmware.vmware_vm_info does not provide instance_UUID of vm
##### SUMMARY
<!--- Explain the problem briefly below -->
The community.vmware.vmware_vm_info module returns a UUID that corresponds to bios_UUID instead of the expected instance_UUID.

##### ISSUE TYPE
- Bug Report

##### COMPONENT NAME
<!--- Write the short name of the module, plugin, task or feature below, use your best guess if unsure -->
community.vmware.vmware_vm_info

##### ANSIBLE VERSION
<!--- Paste verbatim output from "ansible --version" between quotes -->
```
ansible [core 2.13.10]
  config file = /etc/ansible/playbooks/ansible.cfg
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.8/dist-packages/ansible
  ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/local/bin/ansible
  python version = 3.8.10 (default, May 26 2023, 14:05:08) [GCC 9.4.0]
  jinja version = 3.1.2
  libyaml = True
```

##### COLLECTION VERSION
<!--- Paste verbatim output from "ansible-galaxy collection list <namespace>.<collection>"  between the quotes
for example: ansible-galaxy collection list community.general
-->
```
# /usr/local/lib/python3.8/dist-packages/ansible_collections
Collection       Version
---------------- -------
community.vmware 2.10.2

# /root/.ansible/collections/ansible_collections
Collection       Version
---------------- -------
community.vmware 3.8.0

```

##### CONFIGURATION
<!--- Paste verbatim output from "ansible-config dump --only-changed" between quotes -->
```
DEFAULT_LOAD_CALLBACK_PLUGINS(/etc/ansible/playbooks/ansible.cfg) = True
DEFAULT_LOG_PATH(/etc/ansible/playbooks/ansible.cfg) = /etc/ansible/playbooks/logs/ansible.log
DEFAULT_PRIVATE_KEY_FILE(/etc/ansible/playbooks/ansible.cfg) = /etc/ansible/ssh/id_rsa
DEFAULT_ROLES_PATH(/etc/ansible/playbooks/ansible.cfg) = ['/etc/ansible/playbooks/roles']
DEFAULT_STDOUT_CALLBACK(/etc/ansible/playbooks/ansible.cfg) = yaml
DEFAULT_VAULT_PASSWORD_FILE(/etc/ansible/playbooks/ansible.cfg) = /etc/ansible/playbooks/secrets/zim.secret
HOST_KEY_CHECKING(/etc/ansible/playbooks/ansible.cfg) = False
```

##### OS / ENVIRONMENT
<!--- Provide all relevant information below, e.g. target OS versions, network device firmware, etc. -->
Ubuntu 22.04

##### STEPS TO REPRODUCE
<!--- Describe exactly how to reproduce the problem, using a minimal test-case -->

<!--- Paste example playbooks or commands between quotes below -->
```
      - name: Get UUID from given VM Name
        community.vmware.vmware_vm_info:
          hostname: "REDACTED"
          username: 'REDACTED'
          password: '{{ ansibleapi_vsphere }}'
          validate_certs: false
          vm_name: "REDACTED"
        delegate_to: localhost
        register: vm_info

      - name: Print VM UUID
        debug:
          var: vm_info.virtual_machines[0].uuid

```

<!--- HINT: You can paste gist.github.com links for larger files -->

##### EXPECTED RESULTS
<!--- Describe what you expected to happen when running the steps above -->

I would expect to receive the instance_UUID instead of the bios_UUID or both values.

##### ACTUAL RESULTS
<!--- Describe what actually happened. If possible run with extra verbosity (-vvvv) -->

The uuid containd the bios_UUID.

<!--- Paste verbatim command output between quotes -->
```paste below
TASK [Print VM UUID] *************************************************************************************************************************
task path: /etc/ansible/playbooks/zim/zabbix_link_templates_new.yml:54
ok: [REDACTED] =>
  vm_info.virtual_machines[0].uuid: 4220f091-0306-26f9-e481-da71806e33da
```



Discussion:
Files identified in the description:
None

If these files are inaccurate, please update the `component name` section of the description or use the `!component` bot command.

[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: components_banner --->
@Marx1st It looks like the module returns `uuid` from [VirtualMachineConfigSummary(vim.vm.Summary.ConfigSummary)](https://vdc-repo.vmware.com/vmwb-repository/dcr-public/c476b64b-c93c-4b21-9d76-be14da0148f9/04ca12ad-59b9-4e1c-8232-fd3d4276e52c/SDK/vsphere-ws/docs/ReferenceGuide/vim.vm.Summary.ConfigSummary.html). This is indeed documented as `Virtual machine BIOS identification`. We're very close to naming in the API here.

Do you want the `instanceUuid` from there, is this correct?

1. We won't change this, it might be breaking things for other users.
2. We could easily add a new `instance_uuid` or similar to the output. This wouldn't be breaking, so we can do it whenever we like. However, we're facing some [problems in the CI](https://github.com/ansible-collections/community.vmware/issues/1746#issuecomment-1642954137) at the moment so I'm not sure when we have a chance to implement this.
Hi @mariolenz ! Yes, we do need the instanceUuid as this is the only unique id for a vm in a clustered environment: https://blogs.vmware.com/vsphere/2012/02/uniquely-identifying-virtual-machines-in-vsphere-and-vcloud-part-1-overview.html
It would be absolutely great if you could add `instance_uuid` to the output! :)

Resolving patch:
diff --git a/plugins/modules/vmware_cluster_info.py b/plugins/modules/vmware_cluster_info.py
--- a/plugins/modules/vmware_cluster_info.py
+++ b/plugins/modules/vmware_cluster_info.py
@@ -184,7 +184,7 @@
 
 from ansible.module_utils.basic import AnsibleModule
 from ansible.module_utils.six.moves.urllib.parse import unquote
-from ansible_collections.community.vmware.plugins.module_utils.vmware import PyVmomi, vmware_argument_spec, find_datacenter_by_name, find_cluster_by_name,\
+from ansible_collections.community.vmware.plugins.module_utils.vmware import PyVmomi, vmware_argument_spec, find_datacenter_by_name, find_cluster_by_name, \
     get_parent_datacenter
 from ansible_collections.community.vmware.plugins.module_utils.vmware_rest_client import VmwareRestClient
 
diff --git a/plugins/modules/vmware_guest_disk.py b/plugins/modules/vmware_guest_disk.py
--- a/plugins/modules/vmware_guest_disk.py
+++ b/plugins/modules/vmware_guest_disk.py
@@ -516,7 +516,7 @@
 from random import randint
 from ansible.module_utils.basic import AnsibleModule
 from ansible.module_utils._text import to_native
-from ansible_collections.community.vmware.plugins.module_utils.vmware import PyVmomi, vmware_argument_spec,\
+from ansible_collections.community.vmware.plugins.module_utils.vmware import PyVmomi, vmware_argument_spec, \
     wait_for_task, find_obj, get_all_objs, get_parent_datacenter
 from ansible_collections.community.vmware.plugins.module_utils.vm_device_helper import PyVmomiDeviceHelper
 
diff --git a/plugins/modules/vmware_vm_info.py b/plugins/modules/vmware_vm_info.py
--- a/plugins/modules/vmware_vm_info.py
+++ b/plugins/modules/vmware_vm_info.py
@@ -421,6 +421,7 @@ def get_virtual_machines(self):
                 "ip_address": _ip_address,  # Kept for backward compatibility
                 "mac_address": _mac_address,  # Kept for backward compatibility
                 "uuid": summary.config.uuid,
+                "instance_uuid": summary.config.instanceUuid,
                 "vm_network": net_dict,
                 "esxi_hostname": esxi_hostname,
                 "datacenter": None if datacenter is None else datacenter.name,


Test patch: