# Can I run specific role tasks with tags at playbook level?

**URL:** <https://forum.ansible.com/t/can-i-run-specific-role-tasks-with-tags-at-playbook-level/4327>\
**Category:** Get Help\
**Tags:** tags, role, playbook, ansible-core\
**Created:** [March 11, 2024, 7:56pm UTC](https://forum.ansible.com/t/can-i-run-specific-role-tasks-with-tags-at-playbook-level/4327 "2024-03-11T19:56:48Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![marseaplage](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/marseaplage/32/2552_2.png) [@marseaplage](https://forum.ansible.com/u/marseaplage)\
**Post date:** [March 11, 2024, 7:56pm UTC](https://forum.ansible.com/t/can-i-run-specific-role-tasks-with-tags-at-playbook-level/4327/1 "2024-03-11T19:56:48Z")

</div>

I would like to know if I can run specific role tasks with tags at playbook level? I have tried in several ways and in spite of I specify the tags, it always plays all the tasks and I would like just to play those ones that match the specified tag.

ansible version 2.14.6

```auto
##Main playbook: parchadodemo.yml##
---
- name: Parchado demo
  hosts: win
  roles:
   - { role: parchadoWin, tags: 'listadoparches' }

##Tasks role; parchadoWin##
- name: Verifica conectividad del servidor cliente 
  tags: [conectividad, servidor]
  block: 
    - name: Verifica conectividad en el puerto 9025 
      win_shell: Test-NetConnection -ComputerName 192.168.56.23 -Port 9025
      register: connection_output

- name: Lista los parches instalados
  tags: [listadoparches]
  #Devuelve el listado de actualizaciones instaladas, escribe en un archivo de log y lo guarda en un repositorio
  block: 
  - name: Listar actualizaciones intaladas en el servidor y guardarlas en un archivo de log
    win_shell: get-hotfix
    register: listadoactualizaciones

```

---

<div class="post-metadata">

**Author:** ![akira6592](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/akira6592/32/222_2.png) [@akira6592](https://forum.ansible.com/u/akira6592)\
**Post date:** [March 12, 2024, 12:20am UTC](https://forum.ansible.com/t/can-i-run-specific-role-tasks-with-tags-at-playbook-level/4327/2 "2024-03-12T00:20:42Z")

</div>

@marseaplage Hello.

You need to use `ansible-playbook` with `-t` or `--tags` to specify executing tasks by tags.

Could you give us an example of which task you would like to execute when you specify which tag?

---

<div class="post-metadata">

**Author:** ![marseaplage](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/marseaplage/32/2552_2.png) [@marseaplage](https://forum.ansible.com/u/marseaplage)\
**Post date:** [March 12, 2024, 2:00pm UTC](https://forum.ansible.com/t/can-i-run-specific-role-tasks-with-tags-at-playbook-level/4327/3 "2024-03-12T14:00:06Z")

</div>

Hi Akira !! but I want to specify the tags in the main playbook not in the command line, because I do not have access to it. That’s why I create this playbook:

```auto
---
- name: Parchado demo
  hosts: win
  roles:
   - { role: parchadoWin, tags: 'listadoparches' }

```

---

<div class="post-metadata">

**Author:** ![shertel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/shertel/32/1241_2.png) [@shertel](https://forum.ansible.com/u/shertel)\
**Post date:** [March 12, 2024, 2:14pm UTC](https://forum.ansible.com/t/can-i-run-specific-role-tasks-with-tags-at-playbook-level/4327/4 "2024-03-12T14:14:59Z")

</div>

You could configure a default set of tags using [TAGS\_RUN](https://docs.ansible.com/ansible/latest/reference_appendices/config.html#tags-run). Adding tags to a role is equivalent to tagging the individual tasks in the role, see [Tags — Ansible Documentation](https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_tags.html#adding-tags-to-roles) so it’s not possible to do it that way.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [April 11, 2024, 2:15pm UTC](https://forum.ansible.com/t/can-i-run-specific-role-tasks-with-tags-at-playbook-level/4327/5 "2024-04-11T14:15:04Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
