Running Selected Ansible Tasks with Tags
A long playbook that can only be run in full is painful to develop and dangerous to re-run. Three flags fix that: tags select tasks, --limit selects hosts, and --start-at-task skips ahead. Two special tag names change the rules, and both are worth knowing before you meet them by accident.
Scale and Debugging Guide 38 of 45 Beginner
- OSUbuntu 26.04 LTS
- ansible-core2.20.1
- Python3.14.4
- TimeAbout 14 min
always and never are reserved tag names with built-in behaviour. A task tagged always runs whatever you select, unless you explicitly --skip-tags always. A task tagged never runs only when one of its tags is named. They are the mechanism for sanity checks and for destructive steps respectively.
| 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 |
| ANS-B01 | 192.168.0.38 | Ubuntu 26.04 LTS | Managed Node (group: db) | 2 Core | 3 GB | 50 GB |
This guide includes
Use this when a long playbook can only be run in full. This matters because that makes it painful to develop and dangerous to re-run - tags let you run one part, and two special tags behave unlike the rest.
- tagging tasks by what they do
- running only part of the playbook with
--tags - meeting the two special tags, which do not behave like the others
- limiting to some hosts as well as to some tasks
- listing the tasks, and starting part way through
Before you start
- A control node configured as shown in the first step.
- The session runs one tagged playbook several different ways and changes nothing.
-
The configuration this guide assumes
-
A playbook with tags
-
Running only part of it
-
The two special tags
-
Limiting to some hosts
-
Starting part way through