# iterating over data

**URL:** <https://forum.ansible.com/t/iterating-over-data/18592>\
**Category:** Ansible Project\
**Created:** [June 24, 2015, 11:28am UTC](https://forum.ansible.com/t/iterating-over-data/18592 "2015-06-24T11:28:17Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hank\_Beatty](https://avatars.discourse-cdn.com/v4/letter/h/f6c823/32.png) [@Hank\_Beatty](https://forum.ansible.com/u/Hank_Beatty)\
**Post date:** [June 24, 2015, 11:28am UTC](https://forum.ansible.com/t/iterating-over-data/18592/1 "2015-06-24T11:28:17Z")

</div>

Hello,

Given the data below I would like to create a single task that will print the url or the filename without having to specify the hardware (PowerEdge\_xxxxx) or the firmware (bios, idrac, etc.).

Any ideas would be very much appreciated.

Thanks,  
Hank

Something like:

&nbsp;&nbsp;&nbsp;- name: Print firmfware info  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;debug: msg="item0 {{ item.0 }} item1 {{ item.1.url }}"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;with\_indexed\_items: "{{firmware}}"

OR:

&nbsp;&nbsp;&nbsp;- name: Print firmfware info  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;debug: msg="item0 {{ item.0 }} item1 {{ item.1.url }}"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;with\_dict: "{{firmware}}"

---

<div class="post-metadata">

**Author:** ![Hagai\_Kariti](https://avatars.discourse-cdn.com/v4/letter/h/4491bb/32.png) [@Hagai\_Kariti](https://forum.ansible.com/u/Hagai_Kariti)\
**Post date:** [June 27, 2015, 11:56am UTC](https://forum.ansible.com/t/iterating-over-data/18592/2 "2015-06-27T11:56:33Z")

</div>

You can write a small filter plugin that gives you the items of dicts (something that simply returns an `item.values()` or something like that). Then you could do:

vars:

# Will create a list of inner dict values inside a list of parent dict’s values

- firmware\_items: “{{ firmware.values() | map(‘get\_dict\_values’) | list }}”  
tasks:
- debug: var=item.url  
with\_flattened: firmware\_items

Alternatively, I wrote a lookup plugin that allows you do chain lookups and make them iterate on each other. Then you can do this:

tasks:

- debug: item.values.url  
with\_recursive:
- { name: dict, args: firmware }
- { name: dict, args: “{{item.values}}” }

Lookup plugin is here: [Ansible lookup plugin that chains other lookup plugins together and makes them iterate on each other · GitHub](https://gist.github.com/hkariti/d07695b4b9c5a68d8c02)

---

<div class="post-metadata">

**Author:** ![Hank\_Beatty](https://avatars.discourse-cdn.com/v4/letter/h/f6c823/32.png) [@Hank\_Beatty](https://forum.ansible.com/u/Hank_Beatty)\
**Post date:** [July 24, 2015, 12:03pm UTC](https://forum.ansible.com/t/iterating-over-data/18592/3 "2015-07-24T12:03:21Z")

</div>

Hello Hagai,

This got me going. Thank you.

Is there a way to match a given model (given that I set the ‘Model’ var earlier in the playbook)? I need the firmware and that works perfectly but, I need to limit the firmware that goes to a certain model of server.

Thanks,  
Hank

Something like:

- debug: var=Model

- debug: msg={{ item.key }}  
when: item.key == ‘idrac’  
with\_recursive:

- { name: dict, args: firmware, “{{ Model }}” }

- { name: dict, args: “{{item.value}}” }

Here is the output of the above:

TASK: [idrac-firmware | debug var=Model] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [] =\> {  
“var”: {  
“Model”: “PowerEdge\_R730xd”  
}  
}

TASK: [idrac-firmware | debug msg={{ item.key }}] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
skipping: [] =\> (item={‘key’: ‘bios’, ‘value’: {‘url’: ‘[http://downloads.dell.com/FOLDER02797483M/1/BIOS\_CNN4X\_WN64\_2.5.2.EXE](http://downloads.dell.com/FOLDER02797483M/1/BIOS_CNN4X_WN64_2.5.2.EXE)’, ‘search’: ‘none’, ‘target\_version’: ‘2.5.2’, ‘minimum\_version’: ‘none’, ‘filename’: ‘BIOS\_CNN4X\_WN64\_2.5.2.EXE’}})  
skipping: [] =\> (item={‘key’: ‘os\_collector’, ‘value’: {‘url’: ‘[http://downloads.dell.com/FOLDER02775623M/1/Diagnostics\_Application\_5W2KP\_WN64\_OSC\_1.1\_X10-00.EXE](http://downloads.dell.com/FOLDER02775623M/1/Diagnostics_Application_5W2KP_WN64_OSC_1.1_X10-00.EXE)’, ‘search’: ‘none’, ‘target\_version’: 1.1000000000000001, ‘minimum\_version’: ‘none’, ‘filename’: ‘Diagnostics\_Application\_5W2KP\_WN64\_OSC\_1.1\_X10-00.EXE’}})  
skipping: [] =\> (item={‘key’: ‘bios’, ‘value’: {‘url’: ‘[http://downloads.dell.com/FOLDER02868051M/1/BIOS\_XR23Y\_WN64\_1.2.10.EXE](http://downloads.dell.com/FOLDER02868051M/1/BIOS_XR23Y_WN64_1.2.10.EXE)’, ‘search’: ‘none’, ‘target\_version’: ‘1.2.10’, ‘minimum\_version’: ‘none’, ‘filename’: ‘BIOS\_XR23Y\_WN64\_1.2.10.EXE’}})  
ok: [] =\> (item={‘key’: ‘idrac’, ‘value’: {‘url’: ‘[http://downloads.dell.com/FOLDER02881013M/1/iDRAC-with-Lifecycle-Controller\_Firmware\_FM1PC\_WN64\_2.10.10.10\_A00.EXE](http://downloads.dell.com/FOLDER02881013M/1/iDRAC-with-Lifecycle-Controller_Firmware_FM1PC_WN64_2.10.10.10_A00.EXE)’, ‘search’: ‘none’, ‘target\_version’: ‘2.10.10.10’, ‘minimum\_version’: ‘none’, ‘filename’: ‘iDRAC-with-Lifecycle-Controller\_Firmware\_FM1PC\_WN64\_2.10.10.10\_A00.EXE’}}) =\> {  
“item”: {  
“key”: “idrac”,  
“value”: {  
“filename”: “iDRAC-with-Lifecycle-Controller\_Firmware\_FM1PC\_WN64\_2.10.10.10\_A00.EXE”,  
“minimum\_version”: “none”,  
“search”: “none”,  
“target\_version”: “2.10.10.10”,  
“url”: [“http://downloads.dell.com/FOLDER02881013M/1/iDRAC-with-Lifecycle-Controller\_Firmware\_FM1PC\_WN64\_2.10.10.10\_A00.EXE”](http://downloads.dell.com/FOLDER02881013M/1/iDRAC-with-Lifecycle-Controller_Firmware_FM1PC_WN64_2.10.10.10_A00.EXE)  
}  
},  
“msg”: “idrac”  
}  
skipping: [] =\> (item={‘key’: ‘bios’, ‘value’: {‘url’: ‘[http://downloads.dell.com/FOLDER02868051M/1/BIOS\_XR23Y\_WN64\_1.2.10.EXE](http://downloads.dell.com/FOLDER02868051M/1/BIOS_XR23Y_WN64_1.2.10.EXE)’, ‘search’: ‘none’, ‘target\_version’: ‘1.2.10’, ‘minimum\_version’: ‘none’, ‘filename’: ‘BIOS\_XR23Y\_WN64\_1.2.10.EXE’}})  
ok: [] =\> (item={‘key’: ‘idrac’, ‘value’: {‘url’: ‘[http://downloads.dell.com/FOLDER02881013M/1/iDRAC-with-Lifecycle-Controller\_Firmware\_FM1PC\_WN64\_2.10.10.10\_A00.EXE](http://downloads.dell.com/FOLDER02881013M/1/iDRAC-with-Lifecycle-Controller_Firmware_FM1PC_WN64_2.10.10.10_A00.EXE)’, ‘search’: ‘none’, ‘target\_version’: ‘2.10.10.10’, ‘minimum\_version’: ‘none’, ‘filename’: ‘iDRAC-with-Lifecycle-Controller\_Firmware\_FM1PC\_WN64\_2.10.10.10\_A00.EXE’}}) =\> {  
“item”: {  
“key”: “idrac”,  
“value”: {  
“filename”: “iDRAC-with-Lifecycle-Controller\_Firmware\_FM1PC\_WN64\_2.10.10.10\_A00.EXE”,  
“minimum\_version”: “none”,  
“search”: “none”,  
“target\_version”: “2.10.10.10”,  
“url”: [“http://downloads.dell.com/FOLDER02881013M/1/iDRAC-with-Lifecycle-Controller\_Firmware\_FM1PC\_WN64\_2.10.10.10\_A00.EXE”](http://downloads.dell.com/FOLDER02881013M/1/iDRAC-with-Lifecycle-Controller_Firmware_FM1PC_WN64_2.10.10.10_A00.EXE)  
}  
},  
“msg”: “idrac”  
}

---

<div class="post-metadata">

**Author:** ![Hagai\_Kariti](https://avatars.discourse-cdn.com/v4/letter/h/4491bb/32.png) [@Hagai\_Kariti](https://forum.ansible.com/u/Hagai_Kariti)\
**Post date:** [July 24, 2015, 12:44pm UTC](https://forum.ansible.com/t/iterating-over-data/18592/4 "2015-07-24T12:44:02Z")

</div>

Do you mean add conditions for each iteration? No, you cant do that currently. Shouldnt be hard, butnI dont have a lot of time to do it myself.

---

<div class="post-metadata">

**Author:** ![Hank\_Beatty](https://avatars.discourse-cdn.com/v4/letter/h/f6c823/32.png) [@Hank\_Beatty](https://forum.ansible.com/u/Hank_Beatty)\
**Post date:** [July 24, 2015, 2:14pm UTC](https://forum.ansible.com/t/iterating-over-data/18592/5 "2015-07-24T14:14:18Z")

</div>

Yes, adding conditions for each iteration. Exactly.

I can get in there and see if I can modify it.

Are you thinking something like this… :

- debug: msg={{ item.key }}  
with\_recursive:
- { name: dict, args: firmware, conditional: Model } # where Model was set at some past point
- { name: dict, args: “{{item.value}}”, conditional: ‘idrac’ }

Or something else.

Thanks,  
Hank
