CertGrid CertGrid
Hands-on Lab·Ansible

Ansible Play Execution Order

A play has four task sections and they do not run top to bottom in file order. Add role dependencies, which run before the role that declares them, and handlers, which run at the end, and the execution order becomes something worth seeing printed. Each section here announces its own number.

Roles and Collections Guide 26 of 45 Intermediate

Written against the versions above. Role dependencies are deduplicated: a role listed as a dependency by two others runs **once**, at the point of the first. That is usually what you want and is occasionally surprising - a dependency with side effects will not run again for the second consumer.

One managed node. Ordering is a property of the play, not of the fleet.
Server NameIP AddressOSRolesCPURAMHDD
ANS-CTL01192.168.0.36Ubuntu 26.04 LTSAnsible Control Node2 Core3 GB50 GB
ANS-A01192.168.0.37Ubuntu 26.04 LTSManaged Node (group: web)2 Core3 GB50 GB

Before you start

  1. The configuration this guide assumes

  2. Two tiny roles to order

  3. The order a play runs in

  4. Dependencies run once

  5. Where a role's handlers live

Official sources