Listen: One Trigger, Many Handlers
Fan out a single notification.
Listen: One Trigger, Many Handlers is a free DevOps Bootcamp lesson on CoddyKit. This is lesson 4 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.
One Event, Many Reactions
Sometimes one change should trigger several handlers at once. The listen keyword lets many handlers subscribe to a single topic.
Notify a Topic, Not a Name
With listen, a task's notify points at a logical event name instead of one specific handler title.
- name: Update certs
ansible.builtin.copy:
src: site.pem
dest: /etc/ssl/site.pem
notify: restart web stackHandlers Subscribe with listen
Each handler adds a listen line naming the same topic. Every handler listening to that topic fires when it is notified.
handlers:
- name: Restart nginx
ansible.builtin.service:
name: nginx
state: restarted
listen: restart web stackMany Handlers, One Topic
Give several handlers the same listen value and a single notify fans out to all of them. Great for grouped restarts.
- name: Restart php-fpm
ansible.builtin.service:
name: php-fpm
state: restarted
listen: restart web stackDecouple Tasks from Handlers
The big win is decoupling: tasks reference a topic, and you can add or remove handlers without touching the notifying tasks.
Name Still Optional but Useful
A handler with listen can still have a name, which keeps output readable and lets other tasks notify it directly too.
A Handler Can Listen to Many
Give listen a list and one handler responds to several different topics. It reacts to whichever event is notified.
listen:
- restart web stack
- reload tlsStill Idempotent
Topic-based notifications obey the same rules: handlers only fire on changed, and each one still runs at most once per play.
Order Is Still Definition Order
When a topic wakes several handlers, they run in the order they are defined in the handlers list, just like normal handlers.
Common in Shared Roles
Reusable roles use listen so consumers notify a stable topic while the role freely changes its internal handler set.
Notify vs Listen
notify is the signal from a task; listen is the subscription on a handler. Together they turn one event into many actions. 🔔
Quick Check
You want one notify to restart three services at once. What lets multiple handlers respond to a single topic?
Recap
With listen, a task notifies a topic and every subscribed handler fires. This decouples tasks from handlers and scales cleanly. 🎯
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 “Listen: One Trigger, Many Handlers” lesson free?
Yes — any 3 lessons of the DevOps Bootcamp learning path, including “Listen: One Trigger, Many Handlers”, 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 “Listen: One Trigger, Many Handlers”?
Fan out a single notification. 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 4 of 4.
How long does the “Listen: One Trigger, Many Handlers” 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