# WHEN Conditional - When a server is a member of a list of potential groups

**URL:** <https://forum.ansible.com/t/when-conditional-when-a-server-is-a-member-of-a-list-of-potential-groups/23603>\
**Category:** Ansible Project\
**Created:** [January 31, 2017, 12:45pm UTC](https://forum.ansible.com/t/when-conditional-when-a-server-is-a-member-of-a-list-of-potential-groups/23603 "2017-01-31T12:45:34Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![davros1984](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@davros1984](https://forum.ansible.com/u/davros1984)\
**Post date:** [January 31, 2017, 12:45pm UTC](https://forum.ansible.com/t/when-conditional-when-a-server-is-a-member-of-a-list-of-potential-groups/23603/1 "2017-01-31T12:45:34Z")

</div>

Hi,

I’m hoping someone can help with this.

I’m attempting to simply the when logic rather than have to have a long list of or statements.

Currently, the following works for me:

- name: Get Web URL Status  
uri: url=“https://{{ ansible\_fqdn }}:8443/web/servlet” return\_content=yes validate\_certs=no  
register: webRslt  
when: “‘CCIALL’ in group\_names or ‘BATCHALL’ in group\_names”

Is there a way in which I can just write the when statement something like this…  
when: “‘CCIALL’ or ‘BATCHALL’ in group\_names” (This doesn’t work, it just checks all servers rather than only check those which match the 2 groups listed)

Rather than increase the number of Ansible inventory groupings, I’m hoping I can just have a shorter when statement.

Thanks.

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [January 31, 2017, 1:57pm UTC](https://forum.ansible.com/t/when-conditional-when-a-server-is-a-member-of-a-list-of-potential-groups/23603/2 "2017-01-31T13:57:02Z")

</div>

You can use the ‘set theory’ filters

when: group\_names|intersect([‘CCIALL’, ‘BATCHALL’])
