# Task skipping with when condition with multiple groups

**URL:** <https://forum.ansible.com/t/task-skipping-with-when-condition-with-multiple-groups/17288>\
**Category:** Ansible Project\
**Created:** [January 16, 2015, 1:19am UTC](https://forum.ansible.com/t/task-skipping-with-when-condition-with-multiple-groups/17288 "2015-01-16T01:19:58Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michael\_Liu1](https://avatars.discourse-cdn.com/v4/letter/m/4491bb/32.png) [@Michael\_Liu1](https://forum.ansible.com/u/Michael_Liu1)\
**Post date:** [January 16, 2015, 1:19am UTC](https://forum.ansible.com/t/task-skipping-with-when-condition-with-multiple-groups/17288/1 "2015-01-16T01:19:58Z")

</div>

Trying to add a ssh key when a inventory\_hostname belong to certain groups. I would assume that the following is saying when inventory\_hostname belongs to group hadoop OR report.

when: inventory\_hostname in [groups.hadoop , groups.report]

ISSUE: The following task is skipping, even though the host belongs to group report.

- name: add root authorized keys for test key  
authorized\_key: user=root key=“{{ item }}”  
when: inventory\_hostname in [groups.hadoop , groups.report]  
with\_items:
- “ssh-rsa ZzzzzzHV+drdA0PWHRaDw1fqtM/PElGVbysuNCxFJ9JUBebnsbvAqNFQyMDEweMe5xHV+drdA0PWHRaDw1fqtM/PElGVbysuNCxFJ9JUBebnsbvAqNFQyMDEweMe5xHV+drdA0PWHRaDw1fqtM/PElGVbysuNCxFJ9JUBebnsbvAqNFQyMDEweMe5xHV+drdA0PWHRaDw1fqtM/PElGVbysuNCxFJ9JUBebnsbvAqNFQyMDEweMe5x testkey”

TASK: [provision\_server | add root authorized keys for test key] \*\*\*\*\*\*\*\*\*\*\*\*  
skipping: [server1] =\> (item=ssh-rsa ZzzzzzHV+drdA0PWHRaDw1fqtM/PElGVbysuNCxFJ9JUBebnsbvAqNFQyMDEweMe5xHV+drdA0PWHRaDw1fqtM/PElGVbysuNCxFJ9JUBebnsbvAqNFQyMDEweMe5xHV+drdA0PWHRaDw1fqtM/PElGVbysuNCxFJ9JUBebnsbvAqNFQyMDEweMe5xHV+drdA0PWHRaDw1fqtM/PElGVbysuNCxFJ9JUBebnsbvAqNFQyMDEweMe5x testkey)

Is there something wrong with with my syntax for an OR condition for host groups?

Thanks!

---

<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:** [January 16, 2015, 1:45am UTC](https://forum.ansible.com/t/task-skipping-with-when-condition-with-multiple-groups/17288/2 "2015-01-16T01:45:18Z")

</div>

Your “when” statement is a little off.

The following [groups.hadoop , groups.report] would produce something like [[hadoop1, hadoop2], [report1, report2]] so it would be able to match like you are expecting.

I think what you want is probably something more like:

when: inventory\_hostname in groups.hadoop or inventory\_hostname in groups.report

Or maybe even:

when: inventory\_hostname in groups.hadoop|union(groups.report)

---

<div class="post-metadata">

**Author:** ![Michael\_Liu1](https://avatars.discourse-cdn.com/v4/letter/m/4491bb/32.png) [@Michael\_Liu1](https://forum.ansible.com/u/Michael_Liu1)\
**Post date:** [January 16, 2015, 5:42am UTC](https://forum.ansible.com/t/task-skipping-with-when-condition-with-multiple-groups/17288/3 "2015-01-16T05:42:38Z")

</div>

Thanks Matt.

Both of these work as expected. But, is there a more efficient way of stringing together a bunch of ORs? Rather than using…

when: inventory\_hostname in groups.hadoop OR inventory\_hostname in groups.report OR inventory\_hostname in groups.app OR inventory\_hostname in groups.web …

-Mike

---

<div class="post-metadata">

**Author:** ![Michael\_Liu1](https://avatars.discourse-cdn.com/v4/letter/m/4491bb/32.png) [@Michael\_Liu1](https://forum.ansible.com/u/Michael_Liu1)\
**Post date:** [January 16, 2015, 5:45am UTC](https://forum.ansible.com/t/task-skipping-with-when-condition-with-multiple-groups/17288/4 "2015-01-16T05:45:45Z")

</div>

Sorry, Looks like the following worked…

when: inventory\_hostname in groups.hadoop|union(groups.report)|union(groups.app)

Thanks Again!
