CertGrid CertGrid
Hands-on Lab·Ansible

Ansible Handlers and Notification Behaviour

A handler is a task that runs only if something notified it, only once however many times it was notified, and only at the end of the play. Those three rules make it exactly right for restarting a service after a configuration change - and the fourth rule, that a later failure cancels it, is the one that bites.

Plays and Playbooks Guide 15 of 45 Intermediate

Written against the versions above. Handlers are notified by task **name**, so renaming a task's handler breaks the link silently - the notify simply matches nothing. `listen:` gives a handler an additional topic name and lets several handlers respond to one notification, which is more robust for anything shared.

One managed node. Handler behaviour is per play, and a second host would repeat it.
Server NameIP AddressOSRolesCPURAMHDD
ANS-CTL01192.168.0.36Ubuntu 26.04 LTSAnsible Control Node2 Core3 GB50 GB
ANS-A01192.168.0.37Ubuntu 26.04 LTSManaged Node (group: web)2 Core3 GB50 GB

Before you start

  1. The configuration this guide assumes

  2. A handler runs once, at the end

  3. Nothing changed, so nothing is notified

  4. A handler that is skipped because of a failure

  5. force_handlers fixes it

Official sources