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

20 views
Skip to first unread message

davros1984

unread,
Jan 31, 2017, 8:50:27 AM1/31/17
to Ansible Project
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.

Brian Coca

unread,
Jan 31, 2017, 8:57:17 AM1/31/17
to ansible...@googlegroups.com
You can use the 'set theory' filters

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


----------
Brian Coca
Reply all
Reply to author
Forward
0 new messages