# Run handlers after a role

**URL:** <https://forum.ansible.com/t/run-handlers-after-a-role/12766>\
**Category:** Ansible Project\
**Created:** [May 3, 2013, 8:57am UTC](https://forum.ansible.com/t/run-handlers-after-a-role/12766 "2013-05-03T08:57:20Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vincent\_Van\_der\_Kuss](https://avatars.discourse-cdn.com/v4/letter/v/7c8e57/32.png) [@Vincent\_Van\_der\_Kuss](https://forum.ansible.com/u/Vincent_Van_der_Kuss)\
**Post date:** [May 3, 2013, 8:57am UTC](https://forum.ansible.com/t/run-handlers-after-a-role/12766/1 "2013-05-03T08:57:20Z")

</div>

Hi,

I' m wondering if it would be an idea to add the option to run  
handlers from a role after each role when running several roles after  
each other

Today we had the following issue :

We have a role for iptables which uses a template with variables to  
add ports. After that role we configure a mongodb instance

roles:¬  
&nbsp;&nbsp;- rh-proxy¬  
&nbsp;&nbsp;- iptables¬  
&nbsp;&nbsp;- mongodb¬

We had an error in the mongodb role resulting in the handlers not  
being executed and therefore not restarting iptables to open up the  
necessary ports.

maybe something like this might be an option :

roles:¬  
- rh-proxy¬  
- { role: iptables, run\_handlers=1}¬  
- mongodb¬

Just an idea.

V.

---

<div class="post-metadata">

**Author:** ![Serge\_van\_Ginderacht](https://avatars.discourse-cdn.com/v4/letter/s/b782af/32.png) [@Serge\_van\_Ginderacht](https://forum.ansible.com/u/Serge_van_Ginderacht)\
**Post date:** [May 3, 2013, 9:15am UTC](https://forum.ansible.com/t/run-handlers-after-a-role/12766/2 "2013-05-03T09:15:51Z")

</div>

I seem to remember there was some discussion on some ‘flush handlers’ option.

I guess the same problem could happen, when having multiple playbooks ran sequantially, and one of the latter ones depending on a handler action.  
(handlers also run at the end of the whole playbooks, after all plays ran)

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [May 3, 2013, 11:10am UTC](https://forum.ansible.com/t/run-handlers-after-a-role/12766/3 "2013-05-03T11:10:34Z")

</div>

There are several points at which handlers run. They run between plays, and they run immediately after “pre\_tasks” and “roles/tasks” (together) and after “post\_tasks”.

Pre and post tasks are primarily for monitoring and load balancer integration.

Should you want to force handlers to run, you can put in a task like so:

tasks:

- meta: flush\_handlers

anywhere you like.

Of course, “when: foo.changed” with register can often be more clear, if you need something to run immediately.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [May 3, 2013, 11:12am UTC](https://forum.ansible.com/t/run-handlers-after-a-role/12766/4 "2013-05-03T11:12:19Z")

</div>

Small request Serge…

When you don’t know how something works, please ask how it works (or try it), rather than speculate and call it a problem. It would help make the list more positive.

Handlers automatically run between plays, every single time, so this is a non-issue.

Between each play in a multiple-play playbook, handlers _always_ are activated.

---

<div class="post-metadata">

**Author:** ![Vincent\_Van\_der\_Kuss](https://avatars.discourse-cdn.com/v4/letter/v/7c8e57/32.png) [@Vincent\_Van\_der\_Kuss](https://forum.ansible.com/u/Vincent_Van_der_Kuss)\
**Post date:** [May 3, 2013, 11:16am UTC](https://forum.ansible.com/t/run-handlers-after-a-role/12766/5 "2013-05-03T11:16:12Z")

</div>

Michael,

Thanks. Very helpful

V.
