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

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.

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

Built for every Ansible use case in every organization

BacklogZero can generate this kind of automation in your environment, just like it did here.

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