Quiz Entry - updated: 2026.11.26
You add tags: web to an import_tasks and to an include_tasks. Which tasks get the tag in each case?
On an import, every imported task inherits the tag. On an include, only the include task gets it; the tasks in the file don't, unless you pass the tag with apply:.
Tags follow the same rule as when:. Keywords on an import are copied onto every imported task, so --tags web runs all of them.
On an include, the keyword stays on the include task. --tags web selects the include, which then loads the file, but the tasks inside have no web tag and are skipped. To pass keywords on to the tasks inside, use apply:
- name: Include web tasks with the tag applied
ansible.builtin.include_tasks:
file: webserver_tasks.yml
apply:
tags: web
tags: web
The outer tags: web makes --tags web select the include; apply: tags: web gives the tag to every task inside.
Go deeper:
Tag inheritance for includes and the apply keyword (official docs) — why tags on an include stop at the include, and how apply passes them on.
ansible.builtin.include_tasks module (official docs) — the module reference, including the file and apply options.