Tags
Tags label tasks so you can run or skip subsets of a large playbook.
---
- name: Tags demo
hosts: all
become: true
tasks:
- name: Install nginx
apt:
name: nginx
state: present
tags:
- install
- name: Start nginx
service:
name: nginx
state: started
tags:
- startansible-playbook playbooks/tags.yml --tags install
ansible-playbook playbooks/tags.yml --skip-tags start
ansible-playbook playbooks/tags.yml --list-tags--limit
Run the playbook only against selected hosts or groups:
[web]
54.179.68.157
54.254.115.55
[db]
13.200.10.3ansible-playbook playbooks/nginx.yml --limit web
ansible-playbook playbooks/nginx.yml --limit 54.179.68.157
ansible-playbook playbooks/nginx.yml --limit 'web:&staging'Execution strategies
Strategies control how tasks run across hosts.
Linear (default)
All hosts finish task N before starting task N+1.
- hosts: all
strategy: linearFree
Each host runs ahead independently — often faster for long tasks:
---
- name: Free strategy demo
hosts: all
strategy: free
tasks:
- name: Sleep test
shell: sleep 10Serial (rolling)
Update hosts in batches — rolling deployments:
- hosts: web
serial: 1 # or 25% / [1, 2, 5]
tasks:
- name: Deploy app
...Production patterns
| Need | Tool |
|---|---|
| Only install tasks | --tags install |
| One canary host | --limit web-01 |
| Faster independent hosts | strategy: free |
| Zero-downtime rollouts | serial: |
# Dry-run a tagged subset on one host
ansible-playbook site.yml --tags deploy --limit web-01 --check --diffCombine --limit with tags to test production changes on a single host before rolling out to the whole group.