Execute notification at their latest occurance

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

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 :slight_smile:

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

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!