Is there any way to create a nested loop over a dict and a list?

67 views
Skip to first unread message

廖鹏辉

unread,
Sep 17, 2015, 6:42:54 AM9/17/15
to Ansible Project

Say I have two variable like these:

var1:
  key1: val1
  key2: val2
var2:
  - item1
  - item2

Can I loop over these two variables like below?

- shell: echo {{ item.0.value }} {{ item.1 }}
  with_dict: "{{ var1 }}"
  with_items: "{{ var2 }}"

I have no idea to loop over these two variables together and don't wanna change the data type of the variables. Is there any way to achieve this kind of loop in ansible?

Takeshi Yaegashi

unread,
Sep 18, 2015, 2:19:10 AM9/18/15
to Ansible Project
Hello,

You can use with_nested:

    - shell: "echo {{item.0}} {{item.1}}"
      with_nested:
        - var1.values()
        - var2
Regards,
-- 
YAEGASHI Takeshi <yaeg...@debian.org
Reply all
Reply to author
Forward
0 new messages