vmware.vmware_rest
vmware.vmware_rest copied to clipboard
network_moid fails with "More than one object available" when the same network name is defined in multiple virtual switches
SUMMARY
When using vmware.vmware_rest.network_moid against a network name defined in multiple switches the result is a fatal error stating "More than one object available".
ISSUE TYPE
- Bug Report
COMPONENT NAME
vmware.vmware_rest.network_moid
ANSIBLE VERSION
$ ansible --version
ansible [core 2.15.3]
config file = /etc/ansible/ansible.cfg
configured module search path = ['/home/some/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3.11/site-packages/ansible
ansible collection location = /home/some/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/bin/ansible
python version = 3.11.5 (main, Sep 22 2023, 15:34:29) [GCC 8.5.0 20210514 (Red Hat 8.5.0-20)] (/usr/bin/python3.11)
jinja version = 3.1.2
libyaml = True
COLLECTION VERSION
# ansible-galaxy collection list vmware.vmware_rest
# /root/.ansible/collections/ansible_collections
Collection Version
------------------ -------
vmware.vmware_rest 3.0.0
CONFIGURATION
# ansible-config dump --only-changed
CONFIG_FILE() = /etc/ansible/ansible.cfg
OS / ENVIRONMENT
Minimal example executed in a freshly installed RHEL 8.9 machine with latest updates.
# sudo yum install ansible-core python3.11-pip
# pip3.11 install aiohttp
# --> Successfully installed aiohttp-3.9.1 aiosignal-1.3.1 attrs-23.2.0 frozenlist-1.4.1 idna-3.6 multidict-6.0.4 yarl-1.9.4
STEPS TO REPRODUCE
---
- name: Minimal example
hosts: localhost
gather_facts: false
vars:
connection_args:
vcenter_hostname: #hostname
vcenter_username: #username
vcenter_password: #password
vmware_datacenter: "datacenter"
vm_network: "networkname"
tasks:
- name: Fetch network MOID
ansible.builtin.debug:
msg: "{{ lookup('vmware.vmware_rest.network_moid', '/'+vmware_datacenter+'/network/'+vm_network, **connection_args) }}"
EXPECTED RESULTS
If multiple switches are not supported, this should be addressed in the documentation. In that case, the documentation should also contain information on how to narrow the search path (e.g. adding virtual switch name) so that only one MoID is returned.
ACTUAL RESULTS
fatal: [blerb]: FAILED! => {
"msg": "An unhandled exception occurred while running the lookup plugin 'vmware.vmware_rest.network_moid'. Error was a <class 'ansible_collections.cloud.common.plugins.module_utils.turbo.exceptions.EmbeddedModuleUnexpectedFailure'>, original message: More than one object available: [MY_NETWORK_ABC => a-1234, MY_NETWORK_ABC => a-1235, MY_NETWORK_ABC => a-1236].. More than one object available: [MY_NETWORK_ABC => a-1234, MY_NETWORK_ABC => a-1235, MY_NETWORK_ABC => a-1236]."
}
@Soraph Unfortunately the VSphere REST API does not support filtering retrieved networks by switch name, only by datacenter, folder, network name, and network type. The API response to list networks only includes the network name, identifier, and type, so we cannot add that logic in the lookup plugin either. We can update the docs to reflect this.