# Role do something after handler?

**URL:** <https://forum.ansible.com/t/role-do-something-after-handler/19736>\
**Category:** Ansible Project\
**Tags:** fedora\
**Created:** [November 11, 2015, 6:41pm UTC](https://forum.ansible.com/t/role-do-something-after-handler/19736 "2015-11-11T18:41:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dylan\_Martin](https://avatars.discourse-cdn.com/v4/letter/d/8797f3/32.png) [@Dylan\_Martin](https://forum.ansible.com/u/Dylan_Martin)\
**Post date:** [November 11, 2015, 6:41pm UTC](https://forum.ansible.com/t/role-do-something-after-handler/19736/1 "2015-11-11T18:41:34Z")

</div>

Hi all, I have a strange one that I hope you can help me with.

I’m trying to make a role for systemd service unit files. This is the newfangled replacement for good ol’ sysV init scripts in Rhel7, any recent Fedora and a lot of other linux distros.

The workflow is supposed to go something like this.

1. edit/install a unit file, like /etc/systemd/system/myservice.service
2. run systemctl daemon-reload
3. run systemctl enable myservice
4. run systemctl start myservice

daemon-reload tells the systemd daemon to re-read the unit files so it will know you changed something

In ansible, I interpret that as looking like

1. template out unit file
2. notify daemon-reload handler if unit file changed
3. service enable=true state=started name=myservice

The problem is, if I’ve changed the unit file, the daemon-reload runs after the service enable/start, so systemd doesn’t know to re-read the unit file before trying to start/enable the service.

I could just make it run daemon-reload every time the role runs, which kindof sucks. Also, if I’m installing a boatload of unit files, I’d like to do a daemon-reload only once to get them all. I could make the daemon-reload a normal task that only runs when the template changes, but that means I’d be running the daemon-reload once for every unit file, which sucks in the case where I’m installing a boatload of them. I looked at post\_task, but that’s not for roles.

Does anyone know a good way to do this?

Thanks!  
-Dylan

---

<div class="post-metadata">

**Author:** ![jdelaporte](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jdelaporte/32/366_2.png) [@jdelaporte](https://forum.ansible.com/u/jdelaporte)\
**Post date:** [November 11, 2015, 8:46pm UTC](https://forum.ansible.com/t/role-do-something-after-handler/19736/2 "2015-11-11T20:46:00Z")

</div>

Can you have a handler notify another handler?

Otherwise, you could use a post-task in your playbook, I suppose.

---

<div class="post-metadata">

**Author:** ![Ulrich\_Hochholdinger](https://avatars.discourse-cdn.com/v4/letter/u/839c29/32.png) [@Ulrich\_Hochholdinger](https://forum.ansible.com/u/Ulrich_Hochholdinger)\
**Post date:** [November 13, 2015, 6:32am UTC](https://forum.ansible.com/t/role-do-something-after-handler/19736/3 "2015-11-13T06:32:43Z")

</div>

Hi,  
xou can write a handler for every single Action, and notify all desired handlers when needed. Handlers are executed in the order inside the handlers list.

theoretical example:

tasks:

- name: change config  
action: do something  
notify:
- enable\_handler
- reload\_handler
- start\_handler

handlers:

- name: reload\_handler  
service: name=daemon state=reloaded
- name: enable\_handler  
service: name=daemon enabled=yes
- name: start\_handler  
service: name=daemon state=restarted

=\> the handlers are executed in the order of the handlers list as reload … enable … start independend of the order in the notify list. 😉

Cheers  
Ulli

---

<div class="post-metadata">

**Author:** ![Ulrich\_Hochholdinger](https://avatars.discourse-cdn.com/v4/letter/u/839c29/32.png) [@Ulrich\_Hochholdinger](https://forum.ansible.com/u/Ulrich_Hochholdinger)\
**Post date:** [November 13, 2015, 6:32am UTC](https://forum.ansible.com/t/role-do-something-after-handler/19736/4 "2015-11-13T06:32:59Z")

</div>

Hi,  
xou can write a handler for every single Action, and notify all desired handlers when needed. Handlers are executed in the order inside the handlers list.

theoretical example:

tasks:

- name: change config  
action: do something  
notify:
- enable\_handler
- reload\_handler
- start\_handler

handlers:

- name: reload\_handler  
service: name=daemon state=reloaded
- name: enable\_handler  
service: name=daemon enabled=yes
- name: start\_handler  
service: name=daemon state=restarted

=\> the handlers are executed in the order of the handlers list as reload … enable … start independend of the order in the notify list. 😉

Cheers  
Ulli
