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

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

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

@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?

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:

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

You could configure a default set of tags using TAGS_RUN. Adding tags to a role is equivalent to tagging the individual tasks in the role, see Tags — Ansible Documentation so it’s not possible to do it that way.

1 Like

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