# Can't get include\_tasks be selected by a tag

**URL:** <https://forum.ansible.com/t/cant-get-include-tasks-be-selected-by-a-tag/42559>\
**Category:** Get Help\
**Created:** [May 9, 2025, 8:30am UTC](https://forum.ansible.com/t/cant-get-include-tasks-be-selected-by-a-tag/42559 "2025-05-09T08:30:04Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![PieterVoet](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/pietervoet/32/8365_2.png) [@PieterVoet](https://forum.ansible.com/u/PieterVoet)\
**Post date:** [May 9, 2025, 8:30am UTC](https://forum.ansible.com/t/cant-get-include-tasks-be-selected-by-a-tag/42559/1 "2025-05-09T08:30:04Z")

</div>

This is probably just me, but I can’t get this to work…

My playbook:

```auto
---
- name: Test
  hosts: localhost
  gather_facts: false

  roles:
    - { role: myrole, tags: ["one"] }

  tasks:
    - debug: msg="Playbook task"

```

and ‘roles/myrole/tasks/main.yml’ reads :

```auto
---
- 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 :

```auto
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 ?

Thanks !

---

<div class="post-metadata">

**Author:** ![bvitnik](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/bvitnik/32/4132_2.png) [@bvitnik](https://forum.ansible.com/u/bvitnik)\
**Post date:** [May 9, 2025, 10:01am UTC](https://forum.ansible.com/t/cant-get-include-tasks-be-selected-by-a-tag/42559/2 "2025-05-09T10:01:23Z")

</div>

> [@PieterVoet](#):
>
> ```auto
> roles:
> - { role: myrole, tags: ["one"] }
> 
> ```

This adds tag “one” to all of the tasks of the role. So your `roles/myrole/tasks/main.yml` effectively becomes:

```auto
---
- include_tasks: one.yml
  tags:
  - one
  - one

- include_tasks: two.yml
  tags:
  - two
  - one

```

I’d say you just need to remove `tags: ["one"]` from the `roles:` key.

---

<div class="post-metadata">

**Author:** ![PieterVoet](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/pietervoet/32/8365_2.png) [@PieterVoet](https://forum.ansible.com/u/PieterVoet)\
**Post date:** [May 9, 2025, 11:22am UTC](https://forum.ansible.com/t/cant-get-include-tasks-be-selected-by-a-tag/42559/3 "2025-05-09T11:22:27Z")

</div>

That’s clearly explained ! thanks !

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..

Guess I have to switch to :

```auto
- include_role:
    name: myrole
    tasks_from: one

```

thanks for your reply Bojan !

---

<div class="post-metadata">

**Author:** ![bcoca](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/bcoca/32/9269_2.png) [@bcoca](https://forum.ansible.com/u/bcoca)\
**Post date:** [May 9, 2025, 2:21pm UTC](https://forum.ansible.com/t/cant-get-include-tasks-be-selected-by-a-tag/42559/4 "2025-05-09T14:21:02Z")

</div>

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.
