# Execute notification at their latest occurance

**URL:** <https://forum.ansible.com/t/execute-notification-at-their-latest-occurance/13186>\
**Category:** Ansible Project\
**Created:** [July 24, 2013, 9:48am UTC](https://forum.ansible.com/t/execute-notification-at-their-latest-occurance/13186 "2013-07-24T09:48:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bastian\_Kruger](https://avatars.discourse-cdn.com/v4/letter/b/e95f7d/32.png) [@Bastian\_Kruger](https://forum.ansible.com/u/Bastian_Kruger)\
**Post date:** [July 24, 2013, 9:48am UTC](https://forum.ansible.com/t/execute-notification-at-their-latest-occurance/13186/1 "2013-07-24T09:48:06Z")

</div>

Lets say I have a playbook, where I want to add a line to the file /etc/auto.master, to mount some new directories, and then do something with the files in one of those directories. So I would probably write something like this:

> - name: auto.xy is up-to-date  
> template: src=auto.xy.j2 dest=/etc/auto.xy  
> notify:
> - restart autofs

> - name: auto.master is up-to-date  
> lineinfile: dest=/etc/auto.master state=present line=“/xy auto.xy” regexp=^/xy  
> notify:
> - restart autofs

> - name: symlink to file in /xy is present  
> file: src=/xy/xy\_service dest=/etc/init.d/xy\_service state=link

Is there a way I can make sure, that when the symlink is about to be created, the service autofs has definitly been restarted if something has changed? I know I could use “force=yes” to create the symlink anyway, but this doesn’t work if want for instance to execute something in the freshly mounted directory. So how can I achieve this? Is it just a matter of design? Can I group my tasks somehow? I might be really obvious but it seems I can’t figure it out.

And a little follow-up question. Wouldn’t it be nice to execute the notify handlers always when the task was executed that uses this handler?

Thanks,  
Bastian

---

<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:** [July 24, 2013, 3:05pm UTC](https://forum.ansible.com/t/execute-notification-at-their-latest-occurance/13186/2 "2013-07-24T15:05:44Z")

</div>

Yes, you can force handlers to be flushed to run as follows

- meta: flush\_handlers

“Wouldn’t it be nice to execute the notify handlers always when the task was executed that uses this handler?”

No.

Suppose you have a process of changes that all require a service be restarted. There are 10 of these, do you want to restart the service 10 times? Probably not 🙂

---

<div class="post-metadata">

**Author:** ![Bastian\_Kruger](https://avatars.discourse-cdn.com/v4/letter/b/e95f7d/32.png) [@Bastian\_Kruger](https://forum.ansible.com/u/Bastian_Kruger)\
**Post date:** [July 30, 2013, 8:02am UTC](https://forum.ansible.com/t/execute-notification-at-their-latest-occurance/13186/3 "2013-07-30T08:02:18Z")

</div>

Ah thanks, I didn’t know about the meta property 🙂

Yes of course, you’re right. That would indeed be bad. I actually meant to execute all handlers, when the LAST task was executed that uses that handler (I just missed that word). But I think, if using meta: flush\_handlers works, then there is probably no need for that anyway.

Thanks again!
