# when condition based on list

**URL:** <https://forum.ansible.com/t/when-condition-based-on-list/16602>\
**Category:** Ansible Project\
**Created:** [October 24, 2014, 7:50pm UTC](https://forum.ansible.com/t/when-condition-based-on-list/16602 "2014-10-24T19:50:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jacob\_Weber1](https://avatars.discourse-cdn.com/v4/letter/j/94ad74/32.png) [@Jacob\_Weber1](https://forum.ansible.com/u/Jacob_Weber1)\
**Post date:** [October 24, 2014, 7:50pm UTC](https://forum.ansible.com/t/when-condition-based-on-list/16602/1 "2014-10-24T19:50:38Z")

</div>

Is it possible to write something like “when: a and b and c”, but get the list [a,b,c] from a variable?

I have one command that outputs some data, which I register in a variable x. Then I want to see if all items from variable y are included in that output. If I were doing it manually, it might look like: "when x | search(“a”) and x | search(“b”) and x | search(“c”). But I’d like that list to be dynamic.

Any way to do this?

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [October 25, 2014, 12:04am UTC](https://forum.ansible.com/t/when-condition-based-on-list/16602/2 "2014-10-25T00:04:53Z")

</div>

sounds like you mean do something like:

when: a in [‘x’,‘y’,‘z’]

or

when: x.foo in alist

??

---

<div class="post-metadata">

**Author:** ![Jacob\_Weber1](https://avatars.discourse-cdn.com/v4/letter/j/94ad74/32.png) [@Jacob\_Weber1](https://forum.ansible.com/u/Jacob_Weber1)\
**Post date:** [October 25, 2014, 12:33am UTC](https://forum.ansible.com/t/when-condition-based-on-list/16602/3 "2014-10-25T00:33:45Z")

</div>

Not exactly…I want each condition to be a regex on the output of the original command (which also contains a lot of other text). That’s why I was trying to use a “search” filter.
