How to force ansible to restart apache only if there has been a change in configuration ( multiple instances in vars + with_items )

32 views
Skip to first unread message

kzabk...@gmail.com

unread,
Apr 14, 2015, 7:16:03 AM4/14/15
to ansible...@googlegroups.com
Hi, I have problem with my role in ansible. Everything works fine until task call handler. If I changed configuration file (template) only for a single instance of apache, all instances are restarted. How can I force ansible to restart just that instance, the configuration of which I made the change?


Group_vars:

apache:
 -  instance: apache1
    httpd_conf: http_apache1.j2
    etc...

 -  instance: apache2
    httpd_conf: http_apache2.j2
    etc...

Task:
- name: Apache Configuration
  template: src={{ item.httpd_conf }} dest=/{{ item.instance }}/apache/conf/httpd.conf
  with_items: apache
  notify: Restart Apache

Handler:
- name: Restart Apache
  service: name={{ item.instance }} state=restarted
  with_items: apache

TASK: | Apache Configuration] *****************************
changed: [host] => (item=({ 'instance': 'apache1', 'httpd_conf': 'http_apache1.j2'}))
ok: [host] => (item=({ 'instance': 'apache2', 'httpd_conf': 'http_apache2.j2'}))

NOTIFIED: | Restart Apache] ***************************************
changed: [host] => (item=({ 'instance': 'apache1', 'httpd_conf': 'http_apache1.j2'}))
changed: [host] => (item=({ 'instance': 'apache2', 'httpd_conf': 'http_apache2.j2'}))

Thanks in advance for your help.

Reply all
Reply to author
Forward
0 new messages