# Using conditional  "when" with handlers

**URL:** <https://forum.ansible.com/t/using-conditional-when-with-handlers/19430>\
**Category:** Ansible Project\
**Created:** [October 4, 2015, 9:31am UTC](https://forum.ansible.com/t/using-conditional-when-with-handlers/19430 "2015-10-04T09:31:07Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rrohana](https://avatars.discourse-cdn.com/v4/letter/r/e274bd/32.png) [@rrohana](https://forum.ansible.com/u/rrohana)\
**Post date:** [October 4, 2015, 9:31am UTC](https://forum.ansible.com/t/using-conditional-when-with-handlers/19430/1 "2015-10-04T09:31:07Z")

</div>

HI  
I have a code in my playbook like this :

**- name: Copy init scripts**  
**template: src=file-server.conf.j2 dest=/etc/init/file-server.conf**  
**register: init\_script**  
**notify: restart file-server**

**- name: Copy env scripts**  
**template: src=file-server.env.j2 dest=/etc/default/file-server.env**  
**register: env\_script**  
**notify: restart file-server**

I want to notify the handler for both tasks in one “handler”. I tried :  
**- name: restart file-server**  
**service: name=file-server state=restarted**  
**when: {{ item}}.changed**  
**with\_items:**  
**- init\_script**  
**- env\_script**

but it doesn’t work!!  
Any ideas ?

---

<div class="post-metadata">

**Author:** ![David\_Karban](https://avatars.discourse-cdn.com/v4/letter/d/90db22/32.png) [@David\_Karban](https://forum.ansible.com/u/David_Karban)\
**Post date:** [October 4, 2015, 1:45pm UTC](https://forum.ansible.com/t/using-conditional-when-with-handlers/19430/2 "2015-10-04T13:45:04Z")

</div>

Hi, I guess, init\_script and env\_script are much longer, that you thougth. Try:

- debug: var=env\_script to see which part of variable you want to use.

---

<div class="post-metadata">

**Author:** ![Borys\_Borysenko](https://avatars.discourse-cdn.com/v4/letter/b/db5fbb/32.png) [@Borys\_Borysenko](https://forum.ansible.com/u/Borys_Borysenko)\
**Post date:** [October 4, 2015, 8:24pm UTC](https://forum.ansible.com/t/using-conditional-when-with-handlers/19430/3 "2015-10-04T20:24:59Z")

</div>

Hi, actually handlers are triggered once at the end of each block of tasks in a playbook, even were notified by multiple different tasks. I might be wrong, but in your case i don’t understand why you need to use when statement with handler task.
