You need a task to run once per play, not once per host, such as sending a Slack notification.
IntermediateScenarioPlaybook Design, Handlers and Idempotency
Answer
Situation read → A play-wide side effect.
What I'd do →
- ansible.builtin.uri:
url: "{{ slack_webhook }}"
method: POST
body_format: json
body: { text: "Deploy finished" }
run_once: true
delegate_to: localhost
Why → run_once executes on the first host in the batch; delegate_to: localhost makes the call from the controller.
Interview tip → With serial, run_once fires once per batch; use a condition on ansible_play_hosts if you need once overall.
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