community.vmware
community.vmware copied to clipboard
Issue when running vmware_guest while vms in vApp
SUMMARY
When running vmware_guest module in ansible, while the vms are in a vApp, I recive the following error:
File "ansible_collections/community/vmware/plugins/module_utils/vmware.py", line 1315, in get_vm TypeError: argument of type 'NoneType' is not iterable.
ISSUE TYPE
- Bug Report
COMPONENT NAME
community.vmware.vmware_guest
ANSIBLE VERSION
ansible [core 2.12.10]
COLLECTION VERSION
community.vmware 3.5.0
OS / ENVIRONMENT
VMs are located on Vsphere Clients in versions 6.7 and 7. vms with guest os of rhel7.
STEPS TO REPRODUCE
- Have more than one vm created in your vshpere client and move both of the inside the same vApp.
- The playbook runs when the vms do not exist or are not in the vApp. It only accours when they are in a vApp.
- Run the following playbook:
---
- name: Create a new VM
block:
- set_fact:
disk_size: 45
memory: 4096
cpu: 2
- vmware_guest:
hostname: {{ hostname }}
username: {{ username }}
password: {{ password }}
datacenter: Datacenter1
name: {{ hostname }}
template: {{ template_name }}
cluster: VsanCluster
state: poweredoff
datastore: vsanDatastore
folder: {{ vcenter_full_folder }}
validate_certs: False
is_template: no
hardware:
memory_mb: "{{ memory }}"
num_cpus: "{{ cpu }}"
networks:
- name: My Network
start_connected: yes
delegate_to: localhost
EXPECTED RESULTS
Because the vms already exist, the vms will only power off.
ACTUAL RESULTS
I receive a pythonic error from the ansible collection, with the msg "MODULE FAILIURE \n See stdout/stderr for the exact error":
Traceback (most recent call last): File "AnsiballZ_vmware_guest.py", line 107, in
_ansiballz_main() File "AnsiballZ_vmware_guest.py", line 99, in _ansiballz_main invoke module(zipped_mod, temp_path, ANSIBALLZ_PARAMS) File "AnsiballZ_vmware_guest.py", line 47, in invoke_module runpy.run_module(mod_name='ansible_collections.community.vmware.plugins.modules.vmware_guest', init_globals=dict(_module_fqdn='ansible_collections.community.vmware.plugins.modules.vmware_guest', _modlib_path=modlib_path) File python3.8/runpy.py, line 207, in run_module return _run_module_code(codem init_globals, run_name, mod_spec) File python3.8/runpy.py, line 97, in _run_module_code _run_code(code, mod_globals, init_globals) File python3.8/runpy.py, line 87, in _run_code exec(code, run_globals) File "ansible_collections/community/vmware/plugins/modules/vmware_guest.py", line 3597, in
File "ansible_collections/community/vmware/plugins/modules/vmware_guest.py", line 3516, in main File "ansible_collections/community/vmware/plugins/module_utils/vmware.py", line 1315, in get_vm TypeError: argument of type 'NoneType' is not iterable.
The issue seems to rise from the lines: https://github.com/ansible-collections/community.vmware/blob/6bde749991bc8119f0bb6efba536f5b5b4a933ec/plugins/module_utils/vmware.py#L1331-L1337
The function self.get_vm_path(content=self.content, vm_name=vms[0]) returns None, because the vms are in the vApp and then the boolean self.params['folder'] in None raises the error I got.