Selecting or skipping tags when you run a playbook
Once you have added tags to your tasks, includes, blocks, plays, roles, and imports, you can selectively execute or skip tasks based on their tags when you runansible-playbook. Ansible runs or skips all tasks with tags that match the tags you pass at the command line. If you have added a tag at the block or play level, withroles, or with an import, that tag applies to every task within the block, play, role, or imported role or file. If you have a role with several tags and you want to call subsets of the role at different times, eitheruse it with dynamic includes, or split the role into multiple roles.
ansible-playbookoffers five tag-related command-line options:
--tagsall- run all tasks, tagged and untagged except ifnever(default behavior).--tagstag1,tag2- run only tasks with either the tagtag1or the tagtag2(also those taggedalways).--skip-tagstag3,tag4- run all tasks except those with either the tagtag3or the tagtag4ornever.--tagstagged- run only tasks with at least one tag (neveroverrides).--tagsuntagged- run only tasks with no tags (alwaysoverrides).
For example, to run only tasks and blocks tagged eitherconfigurationorpackagesin a very long playbook:
To run all tasks except those taggedpackages:
To run all tasks, even those excluded because are taggednever: