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

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.

You can use the ‘set theory’ filters

when: group_names|intersect([‘CCIALL’, ‘BATCHALL’])