# tags with roles

**URL:** <https://forum.ansible.com/t/tags-with-roles/18781>\
**Category:** Ansible Project\
**Created:** [July 16, 2015, 11:38am UTC](https://forum.ansible.com/t/tags-with-roles/18781 "2015-07-16T11:38:46Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vladimir\_Ondrus](https://avatars.discourse-cdn.com/v4/letter/v/a9a28c/32.png) [@Vladimir\_Ondrus](https://forum.ansible.com/u/Vladimir_Ondrus)\
**Post date:** [July 16, 2015, 11:38am UTC](https://forum.ansible.com/t/tags-with-roles/18781/1 "2015-07-16T11:38:46Z")

</div>

Hi All,

I want to use tags inside the roles, here is my usecase:

I want to execute tasks marked with aaaa from testrole:

[root@wildfly ~/ansible]$ cat test.yml

---

<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:** [July 16, 2015, 7:07pm UTC](https://forum.ansible.com/t/tags-with-roles/18781/2 "2015-07-16T19:07:12Z")

</div>

Hi Vlado,

I think you are misunderstanding the feature. There is no sub  
-election with tags on role definition, when you:  
- {role: testrole, tags: ['aaaa']}

What you are doing is tagging all tasks in testrole with 'aaaa' on top  
of existing tags. So it would look like this once imported:

- name: aaaa tag  
&nbsp;&nbsp;local\_action: command echo  
&nbsp;&nbsp;tags:  
&nbsp;&nbsp;&nbsp;&nbsp;- aaaa

- name: bbbb tag  
&nbsp;&nbsp;local\_action: command echo  
&nbsp;&nbsp;tags:  
&nbsp;&nbsp;&nbsp;&nbsp;- bbbb  
&nbsp;&nbsp;&nbsp;&nbsp;- aaaa

You are not saying 'run only those tagged with 'aaaa', that is not  
possible when specifying a role to import.  
I suggest making 2 roles and only importing the one with the tasks you  
want to execute.

---

<div class="post-metadata">

**Author:** ![Vladimir\_Ondrus](https://avatars.discourse-cdn.com/v4/letter/v/a9a28c/32.png) [@Vladimir\_Ondrus](https://forum.ansible.com/u/Vladimir_Ondrus)\
**Post date:** [July 23, 2015, 11:21am UTC](https://forum.ansible.com/t/tags-with-roles/18781/3 "2015-07-23T11:21:57Z")

</div>

Hi Brain,

thanks for the explanation. Here is similar problem we have:  
We have a download role which should download something from given location(web, maven, local).  
So when location is maven, I dont want to execute http steps.  
But when “when” statement is after include this means that all tasks in included yml will be executed with it.  
But i would like to skip complete yml.

---

<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:** [July 23, 2015, 11:37am UTC](https://forum.ansible.com/t/tags-with-roles/18781/4 "2015-07-23T11:37:12Z")

</div>

the when will be applied to each task, so they will be skipped

---

<div class="post-metadata">

**Author:** ![Vladimir\_Ondrus](https://avatars.discourse-cdn.com/v4/letter/v/a9a28c/32.png) [@Vladimir\_Ondrus](https://forum.ansible.com/u/Vladimir_Ondrus)\
**Post date:** [July 23, 2015, 12:13pm UTC](https://forum.ansible.com/t/tags-with-roles/18781/5 "2015-07-23T12:13:32Z")

</div>

this is current state:

when you want to implement this  
if(x=true)  
task1  
task2  
task3  
task4  
task5  
if(y=true)  
task6  
task7

you should write when to each task:

task1 when x  
task2 when x  
task3 when x  
task4 when x  
task5 when x  
task6 when y  
task7 when y

but when there would be something like goto, you could save many whens, and it would have the desired effect that task would be completely skipped:

goto label when x != true  
task1  
task2  
task3  
tast4  
tast6

label

goto end when y !=true

tast6  
tast7  
end

---

<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:** [July 23, 2015, 12:16pm UTC](https://forum.ansible.com/t/tags-with-roles/18781/6 "2015-07-23T12:16:03Z")

</div>

you can write the when in the include or in 2.0 use blocks
