---
- include_tasks: one.yml
tags: one
- include_tasks: two.yml
tags: two
and the two role taskfiles, ‘one.yml’ : - debug: msg="Role myrole - task ONE"
and ‘two.yml’ - debug: msg="Role myrole - task TWO"
Both taskfiles are executed while running the playbook. Even if ‘-t one’ is specified.
‘include_tasks’ docs say :
tags full
Tags are interpreted by this action but are not automatically inherited by the include tasks, see `apply` Allows for the ‘tags’ keyword to control the selection of this action for execution
which looks what I want.. I want that only ‘roles/myrole/tasks/one.yml’ gets executed.
Can somebody please educate me on this ?
Docs say : When you add a tag to the role option, Ansible applies the tag to ALL tasks within the role.
which I interpreted as 'the tag is specified during role execution, so only tasks that has this task defined will get selected for execution. So I’m wrong..
tags, like most keywords, are inherited except on ‘include’ , roles is an import so both include_tasks already inherited the tags: [ "one" ].
includes do not push their own keywords into inheritance, why they have the apply keyword, so an include_role would function as you expect, but import_role and roles do not.
Also note that the included tasks won’t inherit the tag from the include_tasks, but will inherit tags from roles in this case.