BacklogZero®

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.

Ansible in a Minute — run_once

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: false

How 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

Try it with BacklogZero

Ask BacklogZero to generate this automation for your environment.

Get BacklogZero today

Related guides

Back to Ansible in a Minute

Use run_once to run a task on a single host · Level Up Labs