Using with_items loop with vmware_guest module

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?