ansible-collections / vmware.vmware_rest

Ansible Collection for VMWare (REST modules)
https://ansible-collections.github.io/vmware.vmware_rest/
GNU General Public License v3.0
132 stars 64 forks source link

vmware.vmware_rest.datastore_moid lookup example has wrong path #504

Closed LIV2 closed 3 months ago

LIV2 commented 3 months ago
SUMMARY

The documentation for vmware.vmware_rest.datastore_moid has the following example

- name: lookup MoID of the object
  ansible.builtin.debug: msg="{{ lookup('vmware.vmware_rest.datastore_moid', '/my_dc/host/my_cluster/esxi1.test/ro_datastore', **connection_args) }}"

This returns nothing, I believe the correct path should be "/my_dc/datastore/my_cluster/esxi1.test/ro_datastore"

ISSUE TYPE
COMPONENT NAME

vmware.vmware_rest.datastore_moid

ANSIBLE VERSION

ansible [core 2.15.12] config file = /home/mharlum/.ansible.cfg configured module search path = ['/home/mharlum/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] ansible python module location = /home/mharlum/.pyenv/versions/3.9.18/lib/python3.9/site-packages/ansible ansible collection location = /home/mharlum/.ansible/collections:/usr/share/ansible/collections executable location = /home/mharlum/.pyenv/versions/3.9.18/bin/ansible python version = 3.9.18 (main, Mar 11 2024, 09:36:25) [GCC 13.2.1 20231205 (Red Hat 13.2.1-6)] (/home/mharlum/.pyenv/versions/3.9.18/bin/python3.9) jinja version = 3.1.4 libyaml = True

LIV2 commented 3 months ago

Seems I must be wrong, using that path returns the same value for every host

mikemorency commented 3 months ago

Hi @LIV2 , Im actually working on updating the documentation. VMWare paths are super confusing, Im not sure why all datastores are listed under each host (even if the datastore isnt attached to that host)

Anyway, the correct path should be '/my_dc/datastore/ro_datastore'. Can you let me know if that helps?

mikemorency commented 3 months ago

relevant PR - https://github.com/ansible-collections/vmware.vmware_rest/pull/503

LIV2 commented 3 months ago

That does work but I was trying to get the datastores for specific host(s) so I could rename the default datastore

mikemorency commented 3 months ago

I see. As far as I can tell, this is a limitation with the REST collection. It doesnt seem like the current lookup or (REST) host info module will return the info you want. The community vmware collection has a host info module, which does return just the datastores a host can access. In my testing, it showed the local datastores as well as any iscsi/network datastores that the host can access

---
- hosts: localhost
  gather_facts: false
  tasks:
    - community.vmware.vmware_host_facts:
        esxi_hostname: 'your_esxi_host'
        validate_certs: false

    - debug:
        var: ansible_datastore

Output:

TASK [debug] ***********************************************************************************************************************************************************************************************************************************************
ok: [mikemorency] => {
    "ansible_datastore": [
        {
            "free": "10.00 GB",
            "name": "nfs-datastore",
            "total": "20.00 GB"
        },
        {
            "free": "300.00 GB",
            "name": "datastore1",
            "total": "700.00 GB"
        },
        {
            "free": "1.00 TB",
            "name": "iscsi-ds",
            "total": "3.00 TB"
        }
    ]
}