DevOps / Ansible Interview questions
What happens when a handler is notified multiple times in a play?
Even if several different tasks across a play all call notify on the same handler name, and each of those tasks independently reports changed, Ansible still only executes that handler once, at the point handlers run (by default, at the end of the play).
tasks: - name: Update main config ansible.builtin.template: src: app.conf.j2 dest: /etc/app/app.conf notify: Restart app - name: Update feature flags ansible.builtin.template: src: flags.conf.j2 dest: /etc/app/flags.conf notify: Restart app handlers: - name: Restart app ansible.builtin.service: name: app state: restarted
Internally, Ansible tracks notified handlers as a de-duplicated set per host rather than a queue that fires once per notification, which is exactly the behavior you want: a service that needed to pick up two separate config changes only needs one restart to reflect both, not two back-to-back restarts. This also means handler order is determined by where the handler is defined (in handlers/main.yml or the playbook's handlers section), not by which task happened to notify it first or last.
More Related questions...