# Handlers and failures

**URL:** <https://forum.ansible.com/t/handlers-and-failures/14520>\
**Category:** Ansible Project\
**Created:** [February 7, 2014, 5:51pm UTC](https://forum.ansible.com/t/handlers-and-failures/14520 "2014-02-07T17:51:20Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nadav\_Samet](https://avatars.discourse-cdn.com/v4/letter/n/b38774/32.png) [@Nadav\_Samet](https://forum.ansible.com/u/Nadav_Samet)\
**Post date:** [February 7, 2014, 5:51pm UTC](https://forum.ansible.com/t/handlers-and-failures/14520/1 "2014-02-07T17:51:20Z")

</div>

Hey,

I have a play where I make edits to apache configs which includes a notify “restart apache”. That all works well, except in the following scenario:

1. Task A changes apache configs. Task B runs after task A fails and the play aborts. Apache still runs the old version of the config file.

2. I re-run the playbook, now task A skips since there’s nothing to change and Apache does not get restarted. The play finishes successfully but Apache never got restarted.

One path to go is to immediately restart apache, but that would lead to multiple restarts per run. Any ideas?

-Nadav

---

<div class="post-metadata">

**Author:** ![Walid](https://avatars.discourse-cdn.com/v4/letter/w/ea5d25/32.png) [@Walid](https://forum.ansible.com/u/Walid)\
**Post date:** [February 7, 2014, 8:25pm UTC](https://forum.ansible.com/t/handlers-and-failures/14520/2 "2014-02-07T20:25:32Z")

</div>

can you share your playbook, it is not clear the line of dependencies between A, B, and template file

---

<div class="post-metadata">

**Author:** ![Nadav\_Samet](https://avatars.discourse-cdn.com/v4/letter/n/b38774/32.png) [@Nadav\_Samet](https://forum.ansible.com/u/Nadav_Samet)\
**Post date:** [February 8, 2014, 5:33pm UTC](https://forum.ansible.com/t/handlers-and-failures/14520/3 "2014-02-08T17:33:32Z")

</div>

Here’s an example of the scenario I am describing:

- handlers:  
-name: restart apache  
-service: apache state=restarted

- tasks:

- name: enable apache proxy module [A]  
command; a2enmod proxy creates=/etc/apache/mods-ehabled/proxy.load  
notify: restart apache

- name: task that may fail [B]  
command: this\_may\_fail

On this first run apache gets reconfigured, task B fails so apache doesn’t get restarted. On the second run, the first task is skipped, task B completes successfully, and apache does not get restarted and ends up running the original configuration.

---

<div class="post-metadata">

**Author:** ![James\_Martin2](https://avatars.discourse-cdn.com/v4/letter/j/b9e5f3/32.png) [@James\_Martin2](https://forum.ansible.com/u/James_Martin2)\
**Post date:** [February 9, 2014, 12:34am UTC](https://forum.ansible.com/t/handlers-and-failures/14520/4 "2014-02-09T00:34:07Z")

</div>

I wonder if ansible's retry feature could be made smart enough to note the  
handlers that were notified but not executed. Then on the subsequent run,  
those handlers would get executed.

- James

---

<div class="post-metadata">

**Author:** ![Brent\_Langston](https://avatars.discourse-cdn.com/v4/letter/b/73ab20/32.png) [@Brent\_Langston](https://forum.ansible.com/u/Brent_Langston)\
**Post date:** [February 9, 2014, 12:36am UTC](https://forum.ansible.com/t/handlers-and-failures/14520/5 "2014-02-09T00:36:18Z")

</div>

What if you just abort the remaining tasks, and still run the handlers that have already been set on that run?

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [February 9, 2014, 12:51am UTC](https://forum.ansible.com/t/handlers-and-failures/14520/6 "2014-02-09T00:51:28Z")

</div>

Currently the retry mechanism is an inventory file, so likely not.

The mechanism suggested before is a “force handlers” flag to be used with the option.

–Michael
