# help with with\_items

**URL:** <https://forum.ansible.com/t/help-with-with-items/28466>\
**Category:** Ansible Project\
**Created:** [August 30, 2018, 9:24am UTC](https://forum.ansible.com/t/help-with-with-items/28466 "2018-08-30T09:24:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Karl\_Auer](https://avatars.discourse-cdn.com/v4/letter/k/cc9497/32.png) [@Karl\_Auer](https://forum.ansible.com/u/Karl_Auer)\
**Post date:** [August 30, 2018, 9:24am UTC](https://forum.ansible.com/t/help-with-with-items/28466/1 "2018-08-30T09:24:08Z")

</div>

What I want is the separate lists, like this:

First time through loop, item should be this:

{  
“AllocationId”: “eipalloc-09644c10a5aac6a39”,  
“SubnetId”: “subnet-c1580ba5”

}

Second time through loop, item should be this:

{  
“AllocationId”: “eipalloc-09644c10a5aac6a39”,  
“SubnetId”: “subnet-c1580ba5”  
}

What I get is the name of the variable! As shown below. I get the same effect when I use e.g. set\_facts.

Why? And more importantly, how can I write a loop that will allow me to access e.g. item.SubnetID?

Regards, K.

---

<div class="post-metadata">

**Author:** ![Julien](https://avatars.discourse-cdn.com/v4/letter/j/71e660/32.png) [@Julien](https://forum.ansible.com/u/Julien)\
**Post date:** [August 30, 2018, 9:48am UTC](https://forum.ansible.com/t/help-with-with-items/28466/2 "2018-08-30T09:48:44Z")

</div>

Hello Karl,

Can you try like this?

- hosts: localhost

vars:  
nlb\_subnet\_mappings:

- SubnetId: fred  
AllocationId: 100
- SubnetId: mary  
AllocationId: 200

tasks:

- debug:  
var: item  
with\_items: **“{{ nlb\_subnet\_mappings }}”**

I hope this is these results you are looking for :

PLAY [localhost] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\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}) =\> {  
“item”: {  
“AllocationId”: 100,  
“SubnetId”: “fred”  
}  
}  
ok: [localhost] =\> (item={u’SubnetId’: u’mary’, u’AllocationId’: 200}) =\> {  
“item”: {  
“AllocationId”: 200,  
“SubnetId”: “mary”  
}  
}

PLAY RECAP \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
localhost : ok=2 changed=0 unreachable=0 failed=0

Best Regards

---

<div class="post-metadata">

**Author:** ![Karl\_Auer](https://avatars.discourse-cdn.com/v4/letter/k/cc9497/32.png) [@Karl\_Auer](https://forum.ansible.com/u/Karl_Auer)\
**Post date:** [August 30, 2018, 3:40pm UTC](https://forum.ansible.com/t/help-with-with-items/28466/3 "2018-08-30T15:40:01Z")

</div>

Thanks!
