Interview Prep/Ansible/Roles, Collections and Galaxy

`--tags nginx` skips every task inside a role loaded with `include_role`, even though the include is tagged

AdvancedTroubleshootingRoles, Collections and Galaxy
Answer

Likely causes → Tags on a dynamic include_role or include_tasks apply only to the include statement itself, not to the tasks it loads. The include runs, but the tasks inside do not carry the nginx tag, so they are filtered out.

Fix →

- ansible.builtin.include_role:
    name: nginx
    apply:
      tags: [nginx]
  tags: [nginx]

Or use import_role, which is static and inherits tags to every task.

Prevent → Use the rule: import_* when you need tags and --list-tasks, include_* when you need loops or runtime conditions. Check with ansible-playbook site.yml --tags nginx --list-tasks.

All Ansible questions Roadmap: Ansible

More on Roles, Collections and Galaxy