Interview Prep/Ansible/Playbook Design, Handlers and Idempotency

You need three tasks to notify one handler, and want it to run once. Is that automatic?

BeginnerScenarioPlaybook Design, Handlers and Idempotency
Answer

Situation read → Several changes, one restart.

What I'd do → Just add notify: Restart app to each task.

Why → A handler runs once per play per host no matter how many tasks notified it. Use listen: to let one event trigger several handlers.

handlers:
  - name: Restart app
    ansible.builtin.systemd: { name: app, state: restarted }
    listen: "app config changed"

Interview tip → Notify by listen topic to decouple task names from handler names.

All Ansible questions Roadmap: Ansible

More on Playbook Design, Handlers and Idempotency