# Very basic initial tags support (long) and future plans around tags

**URL:** <https://forum.ansible.com/t/very-basic-initial-tags-support-long-and-future-plans-around-tags/11666>\
**Category:** Ansible Project\
**Created:** [July 11, 2012, 11:55pm UTC](https://forum.ansible.com/t/very-basic-initial-tags-support-long-and-future-plans-around-tags/11666 "2012-07-11T23:55:00Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [July 11, 2012, 11:55pm UTC](https://forum.ansible.com/t/very-basic-initial-tags-support-long-and-future-plans-around-tags/11666/1 "2012-07-11T23:55:00Z")

</div>

Pushed some code to support "tags" on resources, which are an optional thing you can use only if you want them.

Long email as I attempt to explain the concept and my thinking behind it…which is not new in configuration management tools, but how it applies to ansible is new, and  
not everyone may have seen it somewhere else.

=== Part One ===

The idea behind tags is to be able to run only specific parts of a playbook.

For instance, assume we describe our entire infrastructure in a playbook, mapping each "like" group of systems to particular roles, as represented by include files,  
and have one playbook called site.yml:

- hosts: webservers  
&nbsp;&nbsp;tasks:  
&nbsp;&nbsp;&nbsp;&nbsp;- include: tasks/common.yml  
&nbsp;&nbsp;&nbsp;&nbsp;- include: tasks/apache.yml  
&nbsp;&nbsp;&nbsp;  
- hosts: dbservers  
&nbsp;&nbsp;tasks:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- include: tasks/common.yml  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- include: tasks/apache.yml

What happens if I just want to change the NTP server address on all my servers, very quickly? Well, I don't need to run everything, I just want to run  
a particular step in tasks/common.yml -- but not all of them.

So I write that individual task like this:

- name: update ntp server config  
&nbsp;&nbsp;action: template src=templates/ntp.yml dest=/etc/ntp.conf  
&nbsp;&nbsp;tags: ntp

(Note that I could have applied multiple tags by using a YAML list of strings for "tags", but it also takes a string to avoid surprises)

If I run the playbook normally, it does everything to all of my machines:

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ansible-playbook site.yml

Though I can also choose to just run the NTP steps

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ansible-playbook site.yml --tags ntp

If I want more than one tag, I can do that too:

&nbsp;&nbsp;&nbsp;&nbsp;ansible-playbook site.yml -- tags "ntp,acme"

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [July 12, 2012, 12:17am UTC](https://forum.ansible.com/t/very-basic-initial-tags-support-long-and-future-plans-around-tags/11666/2 "2012-07-12T00:17:16Z")

</div>

> - include: "tasks/common.yml as common"

We already have a facility for specifying variables into an include file, for purposes like so:

- include: wordpress.yml user=timmy  
- include: wordpress.yml user=bob

So, might as well just do this:

- include: foo.yml tags=a,b,c

And reuse the existing syntax we have in the language

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [July 12, 2012, 12:38am UTC](https://forum.ansible.com/t/very-basic-initial-tags-support-long-and-future-plans-around-tags/11666/3 "2012-07-12T00:38:12Z")

</div>

Last email for tonight.

the include syntax for tags now works, like this:

include: tasks/common.yml tags=common

And further, the tags code is now super-smart, and will not run a play if none of the tags specified in the play would run.  
This means it's super optimized and won't even run the setup step.

If you had all your hosts in your entire infrastructure in one playbook, and just wanted to run the apache related steps, on machines that happened to care about such things, you could now do this.

(This seems to imply, I think, that if you specify "tags" as an element on a play record, this implies all the tasks in the play are automatically assumed to be tagged with that element. I will open a separate ticket to add this.)

You can see all this illustrated here: [https://github.com/ansible/ansible/blob/devel/examples/playbooks/tags.yml](https://github.com/ansible/ansible/blob/devel/examples/playbooks/tags.yml)

---

<div class="post-metadata">

**Author:** ![jpmens1](https://avatars.discourse-cdn.com/v4/letter/j/e9c0ed/32.png) [@jpmens1](https://forum.ansible.com/u/jpmens1)\
**Post date:** [July 12, 2012, 5:24am UTC](https://forum.ansible.com/t/very-basic-initial-tags-support-long-and-future-plans-around-tags/11666/4 "2012-07-12T05:24:08Z")

</div>

> Pushed some code to support "tags" on resources

Excellent!

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-JP

---

<div class="post-metadata">

**Author:** ![Dag\_Wieers](https://avatars.discourse-cdn.com/v4/letter/d/45deac/32.png) [@Dag\_Wieers](https://forum.ansible.com/u/Dag_Wieers)\
**Post date:** [July 12, 2012, 9:10am UTC](https://forum.ansible.com/t/very-basic-initial-tags-support-long-and-future-plans-around-tags/11666/5 "2012-07-12T09:10:44Z")

</div>

This is exactly what would be needed in our environment. I didn't fully grasp the concept of tags when you mentioned them, but the 3 part explanation captures the various use-cases I was considering when including plays in playbooks.

So I can't wait to test part two and three on our environment.

Thanks !

---

<div class="post-metadata">

**Author:** ![Brad\_Olson](https://avatars.discourse-cdn.com/v4/letter/b/779978/32.png) [@Brad\_Olson](https://forum.ansible.com/u/Brad_Olson)\
**Post date:** [July 17, 2012, 5:36pm UTC](https://forum.ansible.com/t/very-basic-initial-tags-support-long-and-future-plans-around-tags/11666/6 "2012-07-17T17:36:24Z")

</div>

> Thanks, Michael, I was about to hack something experimental to try do just this! Love it when people do my work for me!!
