2016-02-02 55 views
3

我试图遍历与它这样的相关的散列和数组:使用Ansible Playbook可以与with_dict和with_nested一起循环吗?

VAR:

dictionary: 
    aword: [ ant, den ] 
    bword: [ fat, slim ] 

任务:

name: Create symlinks 
command: do something with item[0] over item[1] 
with_nested: 
    - "{{ item.key }}" 
    - "{{ item.value }}" 
with_dict: dictionary 

这是行不通的。我做错了什么或Ansible不支持这种迭代?

+0

我不知道使用的语法,但也许你可以看看过滤器[Combining diction白羊](http://docs.ansible.com/ansible/playbooks_filters.html#combining-hashes-dictionaries) – Michael

回答

5

我解决了这一使用

with_subelements 

这样

瓦尔:

dictionary: 
- name: aword 
    words: 
    - ant 
    - den 
- name: bword 
    words: 
    - fat 
    - slim 

任务:

name: Create symlinks 
command: do something with item.0.name over item.1 
with_subelements: 
    - dictionary 
    - words 
相关问题