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
130 stars 63 forks source link

datastore_moid returns empty string when datastore is in a datastore cluster #359

Open meepsie206 opened 1 year ago

meepsie206 commented 1 year ago
SUMMARY

The datastore_moid lookup only ever returns an empty string when all datastores are in datastore clusters.

ISSUE TYPE
COMPONENT NAME

vmware.vmware_rest.datastore_moid

ANSIBLE VERSION
ansible [core 2.13.4]
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.9/site-packages/ansible
  ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/local/bin/ansible
  python version = 3.9.6 (default, Aug 11 2021, 06:39:25) [GCC 8.5.0 20210514 (Red Hat 8.5.0-3)]
  jinja version = 3.0.3
  libyaml = True
COLLECTION VERSION
tc_vmware_nsxt_ansible [~]# ansible-galaxy collection list vmware.vmware_rest

# /usr/local/lib/python3.9/site-packages/ansible_collections
Collection         Version
------------------ -------
vmware.vmware_rest 2.2.0

# /usr/share/ansible/collections/ansible_collections
Collection         Version
------------------ -------
vmware.vmware_rest 2.2.0
CONFIGURATION
tc_vmware_nsxt_ansible [~]# ansible-config dump --only-changed
ANSIBLE_NOCOWS(/etc/ansible/ansible.cfg) = True
DEFAULT_MANAGED_STR(/etc/ansible/ansible.cfg) = This file is managed by Ansible
DEFAULT_STDOUT_CALLBACK(/etc/ansible/ansible.cfg) = community.general.yaml
DEFAULT_TIMEOUT(/etc/ansible/ansible.cfg) = 60
DISPLAY_SKIPPED_HOSTS(/etc/ansible/ansible.cfg) = False
HOST_KEY_CHECKING(/etc/ansible/ansible.cfg) = False
OS / ENVIRONMENT

vCenter: VMware vCenter Server 7.0.3 build-19717403 OS: Red Hat Enterprise Linux release 8.5 (Ootpa)

This is a container running in docker on a Redhat 7 host. Python 3.9 is installed with microdnf and all packages are install with python3 -m pip install. No venv or virtualenv is in use.

aiohttp 3.8.3

As the network_moid and cluster_moid work as expected, I am 100% confident that it is not an OS / environment issue.

STEPS TO REPRODUCE

Run a simple ansible.builtin.debug as demonstrated below, using the datastore_moid lookup. I have included a network_moid lookup test to show that other lookups work as expected.

- name: Test vmware_rest lookups
  hosts: "localhost"
  gather_facts: false
  vars:
    vcenter_credentials:
      vcenter_hostname: "{{ vc_hostname }}"
      vcenter_password: "{{ vc_password}}"
      vcenter_username: "{{ vc_username }}"
      vcenter_validate_certs: false

  tasks:
    - name: Rest lookup
      ansible.builtin.debug:
        msg:
          - "network: {{ lookup('vmware.vmware_rest.network_moid', '/datacenter/network/network_name', **vcenter_credentials) }}"
          - "datastore: {{ lookup('vmware.vmware_rest.datastore_moid', '/datacenter/datastore/datastore_name', **vcenter_credentials) }}"
          - "datastore with ds cluster: {{ lookup('vmware.vmware_rest.datastore_moid', '/datacenter/datastore/datastore_cluster_name/datastore_name', **vcenter_credentials) }}"
EXPECTED RESULTS

Expected result is the datastore_moid returns the moref of the datastore.

ACTUAL RESULTS

As can be seen from the output below, the network_moid (path: /datacenter/network/network_name) has returned a moref as expected but either format of the datastore_moid lookup is returning an empty string. I would expect the need for the path to include the datastore cluster therefore the output of datastore without ds cluster is probably correct. I include it just to show I have tried many logical combinations but all return an empty string. I can see from the log (if necessary, I can post but will have to sanitise) the recursion finds the datastore folder but then doesn't recurse any further because the only child entities in the folder are storagepod objects (datastore clusters).

PLAY [Test vmware_rest lookups] ****************************************************************************************************************************************************
 [started TASK: vmware_rest lookup on localhost]

TASK [vmware_rest lookup] **********************************************************************************************************************************************************
ok: [localhost] =>
  msg:
  - 'network: dvportgroup-1024'
  - 'datastore: '
  - 'datastore: '

PLAY RECAP *************************************************************************************************************************************************************************
localhost                  : ok=1    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

Using the vCenter MOB, this is the path taken to get to the relevant datastore from the home page:

content > rootFolder: group-d1 (Datacenters) > childEntity: datacenter-1001 (###) > datastoreFolder: group-s1004 (datastore) > childEntity: group-p1012 (###) > childEntity: datastore-2009 (###)

Object types for each moref: group-d1 : ManagedObjectReference:Folder datacenter-1001 : ManagedObjectReference:Datacenter group-s1004 : ManagedObjectReference:Folder group-p1012 : ManagedObjectReference:StoragePod datastore-2009 : ManagedObjectReference:Datastore

Sorry I can not post actual names for either the path or the mob output but trust I have double checked (copied/pasted from the mob) that the names in the playbook are the names in the mob.

As this is my first time raising an issue, as well as feedback on the actual issue I am more than happy to take feedback on the content I have included. I hope I have demonstrated a level of understanding that you can trust but if this is too much detail then please let me know.

goneri commented 1 year ago

Thank you @meepsie206

robbevl commented 1 year ago

Same here. In my case the datastore is not in a cluster but it does have a few subfolders. We have another cluster without any subfolders in the path (of the form: /dc/datastore/VxRail-Virtual-SAN-Datastore) and there the lookup does return the MOID.

Task:

- debug:
    msg: "{{ lookup('vmware.vmware_rest.datastore_moid', '/dc/datastore/cluster/VxRail/VxRail-Virtual-SAN-Datastore-5c92ddfe-1463-4070-98f6-e6569494502f/', vcenter_hostname=vcenter_hostname) }}"

Returning empty string:

ok: [localhost] => msg: ''

My query path consists of:

Managed Object Type: ManagedObjectReference:Datacenter Managed Object ID: datacenter-21

Managed Object Type: ManagedObjectReference:Folder Managed Object ID: group-s24

Managed Object Type: ManagedObjectReference:Folder Managed Object ID: group-s194

Managed Object Type: ManagedObjectReference:Folder Managed Object ID: group-s53987

Managed Object Type: ManagedObjectReference:Datastore Managed Object ID: datastore-40375

Versions: vmware.vmware_rest 2.2.0 vSphere Client version 7.0.3.00700

ARose92 commented 1 year ago

I am having the same issue when trying to find the mold of a datastore that is part of a datastore cluster. I have used the managed object reference to confirm that the path I'm providing is correct and it works for datastores that are not part of a cluster giving me results the same as meepsie206.

Any update on this issue?

mikemorency commented 1 week ago

Hi, we recently over-hauled the lookup plugins, and I believe this issue should be fixed. Would someone with datastore clusters be able to confirm?

The fix is currently available on main and should be included in release 4.1.0