# Using with\_items loop with vmware\_guest module

**URL:** <https://forum.ansible.com/t/using-with-items-loop-with-vmware-guest-module/23597>\
**Category:** Ansible Project\
**Created:** [January 30, 2017, 2:25pm UTC](https://forum.ansible.com/t/using-with-items-loop-with-vmware-guest-module/23597 "2017-01-30T14:25:23Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Matti\_Rantakomi](https://avatars.discourse-cdn.com/v4/letter/m/c6cbf5/32.png) [@Matti\_Rantakomi](https://forum.ansible.com/u/Matti_Rantakomi)\
**Post date:** [January 30, 2017, 2:25pm UTC](https://forum.ansible.com/t/using-with-items-loop-with-vmware-guest-module/23597/1 "2017-01-30T14:25:23Z")

</div>

I’m trying to create new VM with multiple disks using vmware\_guest module. VM details are defined in host\_vars file. Everything is working fine except that I can’t get disk definition working when multiple disks are defined.

I have tried the following:

Disk definition in host\_vars:

`  
vmware\_guest\_disks:  
disk1:  
size\_gb: 20  
datastore: datastore1  
disk2:  
size\_gb: 1  
datastore: datastore1  
disk3:  
size\_gb: 2  
datastore: datastore1

`

Task used create new VM:

`

- name: Create new VM  
vmware\_guest:  
hostname: 192.168.1.2  
username: administrator@vsphere.local  
password: password  
datacenter: datacenter  
cluster: cluster  
name: guestname  
guest\_id: centos64guest  
template: templatename  
validate\_certs: no  
hardware:  
memory\_mb: 1024  
num\_cpus: 1  
customization:  
dns\_servers:
- 8.8.8.8
- 8.8.4.4  
hostname: guesthostname  
domain: guestdomain  
password: password  
networks:
- vlan: 1  
ip: 192.168.1.100  
netmask: 255.255.255.0  
gateway: 192.186.1.1  
disk:
- size\_gb: “{{ item.value.size\_gb }}”
- datastore: “{{ item.value.datastore }}”  
with\_items: “{{ vmware\_guest\_disks | default({}) }}”  
register: deploy  
`

Tasks fails but if it had succeeded as I though it should have created new VM with disks which details have been taken from host\_vars (disks with sizes 20, 1 and 2 GB placed on datastore1). What I’m doing wrong and is there some better way than using with\_items to loop through multiple variables?
