Ich weiß, dass diese Frage schon oft gestellt wurde, aber ich muss etwas hier fehlen!Ansible with_dict erwartet ein dict
Dies ist ein minimales Playbook, um das Problem zu reproduzieren. Hier
ist das Textbuch:
---
- 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 }}"
Hier ist der Ausgang:
$ 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 a dict"}
PLAY RECAP *************************************************************************************
localhost : ok=1 changed=0 unreachable=0 failed=1
Ich würde das Element variablen erwarten in task2 bedruckenden enthalten (zum Beispiel):
key: location1
value: {
id: 1
control_prefix: '10.1.254'
data_prefix: '10.1.100'
}
Was vermissen wir?
Es ist eine Dokumentation Bug - https://github.com/ansible/ansible/issues/17636. – kfreezy