A handler needs to run in the middle of a play, before the next set of tasks.
BeginnerScenarioPlaybook Design, Handlers and Idempotency
Answer
Situation read → Ordering dependency on a handler.
What I'd do →
- ansible.builtin.template: { src: app.conf.j2, dest: /etc/app.conf }
notify: Restart app
- ansible.builtin.meta: flush_handlers
- ansible.builtin.uri: { url: http://localhost:8080/health }
Why → flush_handlers runs pending handlers immediately instead of waiting for the end of the play.
Interview tip → Handlers also flush at the end of each of pre_tasks, roles/tasks and post_tasks sections.
More on Playbook Design, Handlers and Idempotency
Your playbook reports `changed` on every run for a task that runs a shell command. How do you fix it?BeginnerNginx must reload only when its config file actually changes.BeginnerA task fails halfway and its handler never ran, but the config file was changed. The next run shows no change and the service never reloads.AdvancedYou need three tasks to notify one handler, and want it to run once. Is that automatic?BeginnerYou need to deploy a binary only if it is missing or its checksum differs.IntermediateHow do you safely edit one line in `/etc/ssh/sshd_config` and be sure SSH keeps working?Intermediate