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
- OSUbuntu 26.04 LTS
- ansible-core2.20.1
- Python3.14.4
- TimeAbout 14 min
- Reviewed23 August 2026
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.
| Server Name | IP Address | OS | Roles | CPU | RAM | HDD |
|---|---|---|---|---|---|---|
| ANS-CTL01 | 192.168.0.36 | Ubuntu 26.04 LTS | Ansible Control Node | 2 Core | 3 GB | 50 GB |
| ANS-A01 | 192.168.0.37 | Ubuntu 26.04 LTS | Managed Node (group: web) | 2 Core | 3 GB | 50 GB |
Before you start
- A control node configured as shown in the first step.
- The session creates two tiny roles,
baseandappsvc, whereappsvcdepends onbase. Nothing is changed on the managed node.
-
The configuration this guide assumes
-
Two tiny roles to order
-
The order a play runs in
-
Dependencies run once
-
Where a role's handlers live