Conditional execution of tasks failing

16 views
Skip to first unread message

GANA SAGAR

unread,
Jul 26, 2016, 8:33:34 PM7/26/16
to Ansible Project
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



GANA SAGAR

unread,
Jul 28, 2016, 2:32:43 PM7/28/16
to Ansible Project
I took out the curly brackets  from the groups and and the normal bracks..its works fine 
Reply all
Reply to author
Forward
0 new messages