Ansible in a Minute · Ansible Core ·
Use run_once to run a task on a single host
Short answer
Use run_once so Ansible prints a cluster-wide message once instead of on every host.
Request
print a cluster-wide message once with run_once and delegate_facts false
Example
A quick heads-up: Every environment is different. Review and test this example before you run it on systems you care about.
YAML
---
- name: Print a cluster-wide message once with run_once and delegate_facts false
hosts: all
gather_facts: false
tasks:
- name: Print cluster-wide message
ansible.builtin.debug:
msg: "This is a cluster-wide message"
run_once: true
delegate_facts: falseHow it works
run_once executes the task on the first host in the current batch by default. Use it for cluster-wide setup, locking, or messages that must not repeat per host.
When to use it
- Creating a shared lock or marker once per play
- Printing a summary that should appear a single time
Requirements
- Ansible: >=2.14
Validation
- Syntax validated
- Not execution-tested
- Last verified 2026-09-09
Notes
With serial, run_once applies per batch. Confirm which host runs the task before you use it for shared side effects.
Reference
- Controlling where tasks run: delegation and local actions (Ansible docs)
Try it with BacklogZero
Ask BacklogZero to generate this automation for your environment.