Ansible with_dict expects a dict -


i know question has been asked many times before must missing here!

this minimal playbook reproduce issue.

here playbook:

--- - hosts:     - localhost   gather_facts: false   vars:     zones_hash:       location1:         id: 1         control_prefix: '10.1.254'         data_prefix: '10.1.100'       location2:         id: 2         control_prefix: '10.2.254'         data_prefix: '10.2.100'   tasks:     - name: "test1"       debug: var="zones_hash"      - name: "test2"       debug: var="item"       with_dict:       - "{{ zones_hash }}" 

here output:

$ ansible --version ansible 2.3.1.0   config file = /home/configs/_ansible/ansible.cfg   configured module search path = default w/o overrides   python version = 2.7.5 (default, nov  6 2016, 00:28:07) [gcc 4.8.5 20150623 (red hat 4.8.5-11)] $ ansible-playbook playbook.yml  play [localhost] *******************************************************************************  task [test1] *********************************************************************************** ok: [localhost] => {     "zones_hash": {         "location1": {             "control_prefix": "10.1.254",             "data_prefix": "10.1.100",             "id": 1         },         "location2": {             "control_prefix": "10.2.254",             "data_prefix": "10.2.100",             "id": 2         }     } }  task [test2] *********************************************************************************** fatal: [localhost]: failed! => {"failed": true, "msg": "with_dict expects dict"}  play recap ************************************************************************************* localhost                  : ok=1    changed=0    unreachable=0    failed=1 

i expect item variable printed in task2 contain (for example):

key: location1 value: {   id: 1   control_prefix: '10.1.254'   data_prefix: '10.1.100' } 

what missing?

looks ansible's documentation needs updated or you've found bug. http://docs.ansible.com/ansible/latest/playbooks_loops.html#looping-over-hashes uses with_dict syntax seems doesn't work anymore. dictionary needs on same line with_dict.

- name: "test2"   debug: var="item"   with_dict: "{{ zones_hash }}" 

Comments

Popular posts from this blog

javascript - Create a stacked percentage column -

Optimising Firebase database by automatically overwriting data -

javascript - Angular UI-Grid customTemplate directive causing rows to load slowly/? -