Getting a with_dict error when reading through dict:

  • 5 November 2015
  • 3 replies

Hi everyone,
This may not be an issue on the module but certainly for me and I hope I can get an answer from here.
I am trying to run a play book with variables defined in group_vars folder. however when I run the playbook Ansible throws an error saying "fatal: [spine111] => with_dict expects a dict".
What am I doing wrong?
My /roles/tasks/main.yml is:
- name: peerlink.4094 configuration for peer1 only
name: "{{ item.key }}"
ipv4: "{{ item.value.ipv4 }}"
alias_name: "{{ item.value.alias_name }}"
clagd_enable: "{{ item.value.clagd_enable }}"
clagd_peer_ip: "{{ item.value.clagd_peer_ip }}"
clagd_priority: "{{ item.value.clagd_priority }}"
clagd_sys_mac: "{{ item.value.clagd_sys_mac }}"
clagd_args: "{{ item.value.clagd_args }}"
applyconfig: 'yes'
with_dict: cl_interfaces[inventory_hostname]
notify: reload networking
tags: clagd

And my group_vars/peer output is:
alias_name: "Clag_PeerLink"
ipv4: ""
clagd_enable: "yes"
clagd_peer_ip: ""
clagd_priority: "4096"
clagd_args: "-vm"
clagd_sys_mac: "00:00:00:00:00:01"

What am I doing wrong here?

Thanks in advance...

3 replies

Userlevel 5

The process is having a hard time processing the [ ] in the string. It is expecting a dictionary return. What are you trying to reference in that statement? Can you restate that string?
Userlevel 3
Looks like in the group_vars/peer file, your dict is "cl_interface" (singular), and in the with_dict, you need to specify "cl_interfaces" (plural).
Hi Jason,
You hit it right on the head. There was an additional "s" 😞.... It just made me google for last 4 hours 😞.

anyways thank you extremely.
And by the way there was one more error in my variable file that was related to indenting... I had 2 spaces instead of 4 :(

Any way thank you Scott for your advise too.