0

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

1
  • My myvars.yml should be as under but problem persists --- myvms: violet: vmhost: violet-vm vmip: 192.168.1.163 yellow: vmhost: yellow-vm vmip: 192.168.1.164 Commented Aug 9, 2017 at 4:07

2 Answers 2

1

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 }}"
Sign up to request clarification or add additional context in comments.

2 Comments

with_dict: "{{ myvms }}" has not helped. Error remains the same.
Not possible. Either your didn't save your changes, or the error is elsewhere.
0

I think you must delete "-" in you varibles files:

not:

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.