Listen: One Trigger, Many Handlers
Fan out a single notification.
Listen: One Trigger, Many Handlers is a free Ansible Academy lesson on CoddyKit — lesson 4 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.
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. 🎯
Frequently asked questions
Is the “Listen: One Trigger, Many Handlers” lesson free?
Yes — the full text of “Listen: One Trigger, Many Handlers” 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 “Listen: One Trigger, Many Handlers”?
Fan out a single notification. 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 4 of 4, so you can start here or from the beginning and move at your own pace.
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 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