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.
Subscribe for updates
Get an email whenever we publish new guides and blog posts. Unsubscribe anytime.
By subscribing you agree we may email you about Ansible in a Minute and related Level Up Labs updates. We store your address in the same lead sheet as our contact form.
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.
---
- 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)
Built for every Ansible use case in every organization
BacklogZero can generate this kind of automation in your environment, just like it did here.