# Conditional execution of tasks failing

**URL:** <https://forum.ansible.com/t/conditional-execution-of-tasks-failing/22125>\
**Category:** Ansible Project\
**Created:** [July 26, 2016, 3:39pm UTC](https://forum.ansible.com/t/conditional-execution-of-tasks-failing/22125 "2016-07-26T15:39:10Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![GANA\_SAGAR](https://avatars.discourse-cdn.com/v4/letter/g/f6c823/32.png) [@GANA\_SAGAR](https://forum.ansible.com/u/GANA_SAGAR)\
**Post date:** [July 26, 2016, 3:39pm UTC](https://forum.ansible.com/t/conditional-execution-of-tasks-failing/22125/1 "2016-07-26T15:39:10Z")

</div>

Hi,

I am trying to write a task to be executed over 4 groups. 2 of them are based on location ‘sb’ ‘ada’ and 2 of them based on distribution. each combination has separate template.  
sb - redhat - template 1  
sb - aix - template 2  
ada - redhat - template 3  
ada - aix - template 4

hosts  
[redhat]  
redhat1  
redhat2

[sb]  
sdbcf1  
aix2  
aix2

However when I am executing the tasks with the template module using ‘when’ as below. The challenge is, the tasks are being run on 1st group the distribution and are being skipped on the second condition. Where I want the task to be in run only when a server is in both the groups not just one.In this case I dont have a a server thats common. HOw can this be done ? What am I doing wrong ?

- name: Copying our rsyslog template to Redhat servers in sb  
template: src=rsyslog.conf.sb.lx.j2  
dest=/etc/rsyslog.conf.test  
owner=root  
mode=0600  
when: (ansible\_distribution == “RedHat” and “‘sb’ in {{group\_names}}”)  
notify: restart rsyslog

---

<div class="post-metadata">

**Author:** ![GANA\_SAGAR](https://avatars.discourse-cdn.com/v4/letter/g/f6c823/32.png) [@GANA\_SAGAR](https://forum.ansible.com/u/GANA_SAGAR)\
**Post date:** [July 28, 2016, 12:31pm UTC](https://forum.ansible.com/t/conditional-execution-of-tasks-failing/22125/2 "2016-07-28T12:31:21Z")

</div>

I took out the curly brackets from the groups and and the normal bracks…its works fine
