Notify a Handler on Change
Wire a task to fire a handler.
Notify a Handler on Change is a free DevOps Bootcamp lesson on CoddyKit. This is lesson 1 of 4. Any 3 lessons of this learning path are free to read in full — after that, CoddyKit PRO unlocks every lesson, plus hands-on practice with a built-in code editor and a 24/7 AI tutor. It is part of the DevOps Bootcamp learning path, and your progress syncs across the web and the CoddyKit app. The DevOps Bootcamp course includes 4 lessons in total.
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. 🚀
Learn DevOps Bootcamp with an AI tutor — free
Write and run real code in your browser, get instant help from a 24/7 AI tutor, and pick up where you left off on the web or in the app.
- Courses
- 142
- Lessons
- 568
Frequently Asked Questions
Is the “Notify a Handler on Change” lesson free?
Yes — any 3 lessons of the DevOps Bootcamp learning path, including “Notify a Handler on Change”, are free to read in full here on the web. After that, CoddyKit PRO unlocks every lesson, plus interactive practice with a built-in code editor and a 24/7 AI tutor. The DevOps Bootcamp course includes 4 lessons in total.
What will I learn in “Notify a Handler on Change”?
Wire a task to fire a handler. You practise DevOps Bootcamp 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 DevOps Bootcamp?
No prior experience is required. DevOps Bootcamp on CoddyKit is structured for beginners through advanced learners, so you can start here or from the beginning and move at your own pace. This is lesson 1 of 4.
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 DevOps Bootcamp lesson?
Yes. Every DevOps Bootcamp 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