# when item not in key of hash

**URL:** <https://forum.ansible.com/t/when-item-not-in-key-of-hash/18183>\
**Category:** Ansible Project\
**Created:** [May 7, 2015, 11:42am UTC](https://forum.ansible.com/t/when-item-not-in-key-of-hash/18183 "2015-05-07T11:42:49Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rishi](https://avatars.discourse-cdn.com/v4/letter/r/90db22/32.png) [@Rishi](https://forum.ansible.com/u/Rishi)\
**Post date:** [May 7, 2015, 11:42am UTC](https://forum.ansible.com/t/when-item-not-in-key-of-hash/18183/1 "2015-05-07T11:42:49Z")

</div>

Trying to figure out if the following is possible.

I have a hash map e.g.

tools:  
a:  
foobar: 1  
b:  
barfoo: 3

- file: path=/some/dir/{{ item }} state=absent  
with\_items: contents.stdout\_lines  
when: item not in [[list of tools keys]]

I want [[list of tools keys]] to turn into [a,b] basically so the when clause could work. Any way to do this?

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [May 7, 2015, 12:07pm UTC](https://forum.ansible.com/t/when-item-not-in-key-of-hash/18183/2 "2015-05-07T12:07:13Z")

</div>

tools.keys() would give you all of the keys. However in Python/jinja2 this can be shortcut by just specifying tools such as:

when: item not in tools

---

<div class="post-metadata">

**Author:** ![Rishi](https://avatars.discourse-cdn.com/v4/letter/r/90db22/32.png) [@Rishi](https://forum.ansible.com/u/Rishi)\
**Post date:** [May 7, 2015, 8:20pm UTC](https://forum.ansible.com/t/when-item-not-in-key-of-hash/18183/3 "2015-05-07T20:20:52Z")

</div>

Wow simple, thanks!
