Notify service restart before executing next playbook action

My Postfix playbook sends a test email via the mail module. However this fails because postfix has not reloaded the configuration. I now have a manual service restart action in the playbook, however I was wondering if it is possible to have a notify handler executed during a playbook, not at the end of a playbook?

I am not sure if notifiers can be executed during a playbook execution, but i think the manual service restart action can be made conditional based on a particluar action. So for example the task that updates the configuration can be registered and the service restart task can be triggered when the configuration task has changed .

task:

  • name: update the postfix conf
    template: src=/foo dest=/bar
    register: result

  • name: restart postfix
    service: name=postfix state=reloaded
    when_changed: $result

would this help, if idempotent task was the concern.

Benno

Why not make the mail a handler also?

Brian Coca

Because I always want the mail, not only when the postfix config changed…

This is a good idea. Thanks!