# Ansible Tag Usage/Management

**URL:** <https://forum.ansible.com/t/ansible-tag-usage-management/15181>\
**Category:** Ansible Project\
**Created:** [May 7, 2014, 11:14am UTC](https://forum.ansible.com/t/ansible-tag-usage-management/15181 "2014-05-07T11:14:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rod\_naph](https://avatars.discourse-cdn.com/v4/letter/r/e19b73/32.png) [@rod\_naph](https://forum.ansible.com/u/rod_naph)\
**Post date:** [May 7, 2014, 11:14am UTC](https://forum.ansible.com/t/ansible-tag-usage-management/15181/1 "2014-05-07T11:14:47Z")

</div>

Hi

I’m reasonably new to Ansible (about 6 months usage) and have just started looking into how I could best make use of the tagging functionality. At the moment I usually only add tags when I need to run something as a one-off, so create a throwaway tag called ‘foo’, run the playbook and then remove the tag.

When I first looked into tags I was expecting to be able to do it by role, but as tagging is only by task it seems to me at the moment I’d have to add lots of tags (as I have lots of tasks) - and was worried about this becoming a complete mess.

Is anyone able to share/link any tips or tricks for how they use tags, or strategies for how they can best be managed and maintained.

Thanks!

---

<div class="post-metadata">

**Author:** ![Strahinja\_Kustudic2](https://avatars.discourse-cdn.com/v4/letter/s/b4bc9f/32.png) [@Strahinja\_Kustudic2](https://forum.ansible.com/u/Strahinja_Kustudic2)\
**Post date:** [May 7, 2014, 10:47pm UTC](https://forum.ansible.com/t/ansible-tag-usage-management/15181/2 "2014-05-07T22:47:43Z")

</div>

You can add a tag to a whole role like this:

`

- hosts: servers  
roles:
- { role: ‘common’, tags: ‘common’ }
- { role: ‘nginx’, tags: ‘nginx’ }
- { role: ‘php-fpm’, tags: ‘php-fpm’ }

`

---

<div class="post-metadata">

**Author:** ![mhael](https://avatars.discourse-cdn.com/v4/letter/m/919ad9/32.png) [@mhael](https://forum.ansible.com/u/mhael)\
**Post date:** [May 8, 2014, 3:54am UTC](https://forum.ansible.com/t/ansible-tag-usage-management/15181/3 "2014-05-08T03:54:00Z")

</div>

Also, if you want to assign a specific tag in the role itself (as opposed to assigning it in every playbook using this role) - you can do it with include. Just move all the tasks from role’s main.yml to a separate file and put include with tag in main.yml instead, like this:

`

- include: role\_tasks.yml tags=sometag

`
