title: Ansible handler using if statements
body: <p>I have an apache playbook which needs to run on centos 7 and centos 6. I want the handler triggered based on distribution major version. I have a handler called <code>restart apache on 7</code> and another one <code>restart apache on 6</code>. </p>
  
  <p>My <code>handlers/main.yml</code> looks like this</p>
  
  <pre><code> ---
   - name: restart apache on 7
    systemd: name=httpd state=restarted
  
   - name: restart apache on 6
     service: name=httpd state=restarted
  </code></pre>
  
  <p>I have tried doing the following in my <code>tasks/main.yml</code>but seem to be running into syntax issues pertaining to the notify script.</p>
  
  <pre><code>- name: Copy custom configs
    copy:
     dest: /etc/httpd/conf/
     src: httpd.conf
     owner: root 
    notify: {%if ansible_distribution_major_version &gt;= '7.0' %}restart apache on 7 {%else%} restart apache on 6 {%endif%}
  </code></pre>
  
  <p>Any clues on how to write the notify statement to achieve my goal?</p>