# Using when: x in y if y is a list of dicts

**URL:** <https://forum.ansible.com/t/using-when-x-in-y-if-y-is-a-list-of-dicts/19041>\
**Category:** Ansible Project\
**Created:** [August 18, 2015, 9:43am UTC](https://forum.ansible.com/t/using-when-x-in-y-if-y-is-a-list-of-dicts/19041 "2015-08-18T09:43:49Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rob\_White](https://avatars.discourse-cdn.com/v4/letter/r/71c47a/32.png) [@Rob\_White](https://forum.ansible.com/u/Rob_White)\
**Post date:** [August 18, 2015, 9:43am UTC](https://forum.ansible.com/t/using-when-x-in-y-if-y-is-a-list-of-dicts/19041/1 "2015-08-18T09:43:49Z")

</div>

Hi guys,

I wonder if anyone knows if it’s possible do use the ‘in’ clause with a list of dicts.

I have a list that looks like this:

[{u’state’: None, u’id’: u’i-233b31yy’}, {u’state’: None, u’id’: u’i-2a2281xx’}]

I want to add\_host if an id is not in the list, something like:

`  
vars:  
mylist:

- {u’state’: None, u’id’: u’i-233b31yy’}
- {u’state’: None, u’id’: u’i-2a2281xx’}  
tasks:  
local\_action:  
module: add\_host  
name: “{{ ansible\_ec2\_local\_ipv4 }}”  
group: not\_in\_elb  
when: ansible\_ec2\_instance\_id not in mylist  
`

The above fails because the list items are dicts. How can I just look at the id value of each dict in the list?
