Reputation: 25
Trying to create multiple VMs using ansible module vmware_guest. I am getting error
"msg": "with_dict expects a dict"
"failed": true
I am using myvars.yml content as under:
---
myvms:
violet:
- vmhost: violet-vm
vmip: 192.168.1.163
yellow:
- vmhost: yellow-vm
vmip: 192.168.1.164
My task file vmspin.yml is:
- name: create the VM
hosts: localhost
connection: local
vars_files:
- myvars.yml
tasks:
- vmware_guest:
hostname: "myhost"
username: "[email protected]"
password: "password"
datacenter: dc1
name:
- name: "{{item.value.vmhost}}"
disk:
- size_gb: 4
type: thin
datastore: Datastore1
networks:
- name: VM Network
ip: "{{item.value.vmip}}"
netmask: 255.255.255.0
template: rhel7_base_template
with_dict:
- "{{myvms}}"
register: deploy
Any solution
Upvotes: 0
Views: 3179
Reputation: 1
I think you must delete "-" in you varibles files:
myvms:
violet:
- vmhost: violet-vm
vmip: 192.168.1.163
yellow:
- vmhost: yellow-vm
vmip: 192.168.1.164
but:
myvms:
violet:
vmhost: violet-vm
vmip: 192.168.1.163
yellow:
vmhost: yellow-vm
vmip: 192.168.1.164
Upvotes: 0
Reputation: 68319
By saying:
with_dict:
- "{{myvms}}"
you pass a list with single element that contains your myvms
dict into lookup.
Replace it with just:
with_dict: "{{ myvms }}"
Upvotes: 1