Notify a Handler on Change
Wire a task to fire a handler.
Notify a Handler on Change is a free Ansible Academy lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Ansible Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Restart Only When Needed
Restarting a service on every run is wasteful and risky. A handler lets you restart it only when something actually changed.
What a Handler Is
A handler is just a task that sits idle until a regular task tells it to run. Think of it as an action waiting for a signal.
The notify Keyword
You connect a task to a handler with the notify keyword. The value is the exact name of the handler to wake up.
- name: Copy nginx config
ansible.builtin.copy:
src: nginx.conf
dest: /etc/nginx/nginx.conf
notify: Restart nginxNames Must Match
The string in notify must match the handler's name letter for letter. A typo means the handler silently never fires.
Notify Fires on changed
A handler is notified only when its task reports changed. If the task is already in the desired state, nothing is triggered.
ok Means No Notify
When a task returns ok, Ansible skips the notify entirely. That is why a second run usually restarts nothing. ✅
A Task Can Notify Many
One task may notify several handlers by giving notify a list. Each named handler gets queued when the task changes.
notify:
- Restart nginx
- Reload firewallNotifications Are Queued
Notifying does not run the handler right away. Ansible queues it and runs it later, after the play's tasks finish.
Each Handler Runs Once
If five tasks all notify the same handler, it still runs once. Ansible deduplicates queued notifications automatically.
Why This Saves Downtime
Because the restart only happens on real change, unchanged servers keep serving traffic. This is the heart of safe, idempotent automation.
A Complete Picture
A task changes a file, then notify queues the restart. Tasks finish, then the handler restarts the service. Clean and minimal.
Quick Check
When does a notified handler actually get triggered?
Recap
You learned that notify wires a task to a handler that runs only on change. Names must match, and Ansible queues each handler to run just once. 🚀
Frequently asked questions
Is the “Notify a Handler on Change” lesson free?
Yes — the full text of “Notify a Handler on Change” is free to read here on the web, and the Ansible Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Ansible Academy course, upgrade to CoddyKit PRO.
What will I learn in “Notify a Handler on Change”?
Wire a task to fire a handler. You practise Ansible Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Ansible Academy?
No prior experience is required. Ansible Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Notify a Handler on Change” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Ansible Academy lesson?
Yes. Every Ansible Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Notify a Handler on Change
- Defining Handlers & Restart Patterns
- When Handlers Run & flush_handlers
- Listen: One Trigger, Many Handlers