# Using tags in a playbook

**URL:** <https://forum.ansible.com/t/using-tags-in-a-playbook/18241>\
**Category:** Ansible Project\
**Tags:** ubuntu\
**Created:** [May 15, 2015, 6:56pm UTC](https://forum.ansible.com/t/using-tags-in-a-playbook/18241 "2015-05-15T18:56:09Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Roger\_Sherman1](https://avatars.discourse-cdn.com/v4/letter/r/c68b51/32.png) [@Roger\_Sherman1](https://forum.ansible.com/u/Roger_Sherman1)\
**Post date:** [May 15, 2015, 6:56pm UTC](https://forum.ansible.com/t/using-tags-in-a-playbook/18241/1 "2015-05-15T18:56:09Z")

</div>

I’m still pretty new to Ansible, and I’m trying to figure out the proper method for setting up a role, and then calling only a couple of tasks from that role from a playbook.

The reason I’m doing so, is I have a group of nodes that need two tomcat instances running on top of a base instance, but I also have another group that only needs one tomcat instance. So I’ve created a very simple role:

> * * *
> 
> - name: install tomcat7  
> sudo: True  
> apt: name=tomcat7 update\_cache=yes cache\_valid\_time=3600  
> tags:
> - wowza
> - name: create directory structure for tomcat\_1  
> sudo: True  
> file: path=/var/opt/tomcat\_1/{{ item }} state=directory owner=tomcat7 group=nogroup  
> with\_items:
> - bin
> - conf
> - logs
> - temp
> - webapps
> - work  
> tags:
> - java\_nodes
> - name: create lib link  
> file: src=/usr/share/tomcat7/lib dest=/var/opt/tomcat\_1/lib state=link  
> tags:
> - java\_nodes
> - name: create deeper directory structure for tomcat\_1  
> sudo: True  
> file: path=/var/opt/tomcat\_1/conf/Catalina/localhost state=directory owner=tomcat7 group=nogroup  
> tags:
> - java\_nodes
> - name: create symlink under tomcat\_1/bin  
> sudo: True  
> file: src=/usr/share/tomcat7/bin/bootstrap.jar dest=/var/opt/tomcat\_1/bin/bootstrap.jar owner=tomcat7 group=nogroup state=link  
> tags:
> - java\_nodes
> - name: create file structure for tomcat\_2  
> sudo: True  
> file: path=/var/opt/tomcat\_2/{{ item }} state=directory owner=tomcat7 group=nogroup  
> with\_items:
> - bin
> - conf
> - logs
> - temp
> - webapps
> - work  
> tags:
> - java\_nodes
> - name: create lib link  
> file: src=/usr/share/tomcat7/lib dest=/var/opt/tomcat\_2/lib state=link  
> tags:
> - java\_nodes
> - name: create deeper directory structure for tomcat\_2  
> sudo: True  
> file: path=/var/opt/tomcat\_2/conf/Catalina/localhost state=directory owner=tomcat7 group=nogroup  
> tags:
> - java\_nodes
> - name: create symlink under tomcat\_2/bin  
> sudo: True  
> file: src=/usr/share/tomcat7/bin/bootstrap.jar dest=/var/opt/tomcat\_2/bin/bootstrap.jar owner=tomcat7 group=nogroup state=link  
> tags:
> - java\_nodes

And I’m executing it from this playbook:

> * * *
> 
> - name: Install Oracle Java 7 and tomcat  
> hosts: basic\_java  
> sudo: True  
> roles:
> - java
> - { role: tomcat, tags: ‘wowza’ }

According to the documentation, that should be possible:

[http://docs.ansible.com/playbooks\_tags.html](http://docs.ansible.com/playbooks_tags.html)

> You may also apply tags to roles:
> 
> ```auto
> roles:
> - { role: webserver, port: 5000, tags: ['web', 'foo'] }
> 
> ```

I have tried this a couple of different ways:

> { role: tomcat, tags: ‘wowza’ }

> { role: tomcat, tags: ‘wowza’, skip-tags ‘java\_nodes’ }

> { role: tomcat, skip-tags: ‘java\_nodes’ }

> 

But they all execute the entire role.

I’m using Ansible 1.8.2, and running it from a mac, on Ubuntu nodes in Vagrant.

Am I incorrect in my interpretation of the documentation? Is this not an allowable way to use tags? And if so, is there a best practices way to achieve what I’m going for, here? I’d hate to have to create a second tomcat role - that seems inelegant.

Thank you, and I’m looking forward to your thoughts.

---

<div class="post-metadata">

**Author:** ![Kyle](https://avatars.discourse-cdn.com/v4/letter/k/848f3c/32.png) [@Kyle](https://forum.ansible.com/u/Kyle)\
**Post date:** [May 19, 2015, 7:22pm UTC](https://forum.ansible.com/t/using-tags-in-a-playbook/18241/2 "2015-05-19T19:22:08Z")

</div>

Did you try with the brackets, as indicated in the documentation you pasted in?

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [May 19, 2015, 7:42pm UTC](https://forum.ansible.com/t/using-tags-in-a-playbook/18241/3 "2015-05-19T19:42:12Z")

</div>

when you apply tags to roles, you actually ADD that tag to each task  
in the role, there is no way to use tags in a role declaration to  
select a subset of tasks.
