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

**URL:** <https://forum.ansible.com/t/how-to-force-ansible-to-restart-apache-only-if-there-has-been-a-change-in-configuration-multiple-instances-in-vars-with-items/17971>\
**Category:** Ansible Project\
**Created:** [April 14, 2015, 6:57am UTC](https://forum.ansible.com/t/how-to-force-ansible-to-restart-apache-only-if-there-has-been-a-change-in-configuration-multiple-instances-in-vars-with-items/17971 "2015-04-14T06:57:39Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![kzabkowski](https://avatars.discourse-cdn.com/v4/letter/k/f17d59/32.png) [@kzabkowski](https://forum.ansible.com/u/kzabkowski)\
**Post date:** [April 14, 2015, 6:57am UTC](https://forum.ansible.com/t/how-to-force-ansible-to-restart-apache-only-if-there-has-been-a-change-in-configuration-multiple-instances-in-vars-with-items/17971/1 "2015-04-14T06:57:39Z")

</div>

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.
