# run only selected tags

**URL:** <https://forum.ansible.com/t/run-only-selected-tags/17455>\
**Category:** Ansible Project\
**Created:** [February 5, 2015, 1:26pm UTC](https://forum.ansible.com/t/run-only-selected-tags/17455 "2015-02-05T13:26:37Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Denis\_J\_Cirulis](https://avatars.discourse-cdn.com/v4/letter/d/ac8455/32.png) [@Denis\_J\_Cirulis](https://forum.ansible.com/u/Denis_J_Cirulis)\
**Post date:** [February 5, 2015, 1:26pm UTC](https://forum.ansible.com/t/run-only-selected-tags/17455/1 "2015-02-05T13:26:37Z")

</div>

Hello,

As I composed one role which partially can be reused in some others I tried the following syntax in playbook:

hosts: test  
sudo: True  
roles:

- common
- { role: big, tags: [‘aaa’, ‘bbb’]}

But looks like tags functionality is not working. If I run playbook with --tags arg it runs only matching tags, but when I want to list all tags to execute in roles it runs the whole role.

How can I overcome this ?

---

<div class="post-metadata">

**Author:** ![Giovanni\_Tirloni](https://avatars.discourse-cdn.com/v4/letter/g/71c47a/32.png) [@Giovanni\_Tirloni](https://forum.ansible.com/u/Giovanni_Tirloni)\
**Post date:** [February 5, 2015, 2:33pm UTC](https://forum.ansible.com/t/run-only-selected-tags/17455/2 "2015-02-05T14:33:14Z")

</div>

Sorry, perhaps I didn't get it. Can you clarify? The --tags option is  
used to limit which tags are considered.

You want to \*list\* all the tags contained in a given playbook? I don't  
think there is an option for that.

Giovanni

---

<div class="post-metadata">

**Author:** ![Timothy\_Gerla](https://avatars.discourse-cdn.com/v4/letter/t/977dab/32.png) [@Timothy\_Gerla](https://forum.ansible.com/u/Timothy_Gerla)\
**Post date:** [February 5, 2015, 2:48pm UTC](https://forum.ansible.com/t/run-only-selected-tags/17455/3 "2015-02-05T14:48:33Z")

</div>

> As I composed one role which partially can be reused in some others I  
> tried the following syntax in playbook:
> 
> hosts: test  
> sudo: True  
> roles:  
> &nbsp;&nbsp;- common  
> &nbsp;&nbsp;- { role: big, tags: ['aaa', 'bbb']}
> 
> But looks like tags functionality is not working. If I run playbook with  
> --tags arg it runs only matching tags, but when I want to list all tags to  
> execute in roles it runs the whole role.

This doesn't mean "run tasks tagged aaa and bbb in role big", it means "tag  
all of role big with tags aaa and bbb". This is so you can have a playbook  
that calls certain roles conditionally, based on the tags you're executing.

If you find yourself trying to call parts of a role, I would suggest  
breaking that role up into smaller roles and calling those as needed. The  
point of a role is to be a single useful set of tasks that is executed as a  
group, so if your roles are not decomposed enough, you will probably have  
trouble.

Hope this helps!

-Tim

---

<div class="post-metadata">

**Author:** ![Denis\_J\_Cirulis](https://avatars.discourse-cdn.com/v4/letter/d/ac8455/32.png) [@Denis\_J\_Cirulis](https://forum.ansible.com/u/Denis_J_Cirulis)\
**Post date:** [February 5, 2015, 3:11pm UTC](https://forum.ansible.com/t/run-only-selected-tags/17455/4 "2015-02-05T15:11:21Z")

</div>

Thanks Timothy, that’s exactly what I was thinking of. Will just decompose the role into smaller sets of tasks and that’s all.  
Just saw in ansible documentation that:

You may also apply tags to roles:

```auto
roles:
  - { role: webserver, port: 5000, tags: ['web', 'foo'] }

```

and thought it will execute tasks by tags 🙂
