# vmware\_guest module and loop

**URL:** <https://forum.ansible.com/t/vmware-guest-module-and-loop/26030>\
**Category:** Ansible Project\
**Tags:** vmware\
**Created:** [November 15, 2017, 12:45pm UTC](https://forum.ansible.com/t/vmware-guest-module-and-loop/26030 "2017-11-15T12:45:28Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![zerros](https://avatars.discourse-cdn.com/v4/letter/z/9de0a6/32.png) [@zerros](https://forum.ansible.com/u/zerros)\
**Post date:** [November 15, 2017, 12:45pm UTC](https://forum.ansible.com/t/vmware-guest-module-and-loop/26030/1 "2017-11-15T12:45:28Z")

</div>

hello,

Forgive me in advance for my bad english.

I’m trying to use vmware\_guest module with loops to create disks in the created vm.  
But I don’t understand how to do this. The idea is to create a random number of disk.

My code:  
`

- name: “Creating a VM based on template”  
vmware\_guest:  
datacenter: “{{ vmware\_datacenter }}”  
cluster: “{{ vmware\_cluster }}”  
hostname: “{{ vcenter\_host }}”  
username: “{{ vcenter\_user }}”  
password: “{{ vcenter\_password }}”  
validate\_certs: no  
folder: “{{ v\_folder | default(‘/’) }}”  
name: “{{ v\_hostname }}”  
annotation: “{{ ansible\_date\_time.date }} - VM creation {{ v\_hostname }} using ansible”  
state: poweredon  
template: “{{ vmware\_template }}”  
**disk** \*\*:\*\*  
**- size\_gb: “{{ item }}”**  
**type: “thin”**  
**datastore: “{{ vmware\_datastore }}”**  
hardware:  
memory\_mb: “{{ v\_memory\_size }}”  
num\_cpus: “{{ v\_cpu\_number }}”  
scsi: paravirtual  
networks:
- name: “{{ vmware\_network }}”  
vlan: “{{ v\_vlan\_id }}”  
ip: “{{ v\_ip }}”  
netmask: “{{ v\_netmask | default(‘255.255.255.0’) }}”  
gateway: “{{ v\_gateway }}”  
**with\_items: “{{ disktest }}”**  
delegate\_to: localhost

`

And I execute:

`ansible-playbook -vvv -e '{"vmware_network":"MYNETWORK","v_hostname":"MYHOSTNAME","v_memory_size":2048,"v_cpu_number":1,"v_ip":"xxx.xxx.xxx.xxx","v_netmask":"255.255.255.0","v_gateway":"xxx.xxx.xxx.xxxx","v_vlan_id":xx}' **-e '{"disktest": [20,50]}'** vmware.yml`

But it doesn’t work:

“msg”: “Provided disks configuration has less disks than the target object (1 vs 2)”

I think it’s just a global loop understanding rather thant a vmware\_guest problem. Any idea please ?

Thanks in advance 🙂
