# playbook includes and tags

**URL:** <https://forum.ansible.com/t/playbook-includes-and-tags/17060>\
**Category:** Ansible Project\
**Created:** [December 15, 2014, 12:07pm UTC](https://forum.ansible.com/t/playbook-includes-and-tags/17060 "2014-12-15T12:07:44Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Adam\_Guthrie](https://avatars.discourse-cdn.com/v4/letter/a/f19dbf/32.png) [@Adam\_Guthrie](https://forum.ansible.com/u/Adam_Guthrie)\
**Post date:** [December 15, 2014, 12:07pm UTC](https://forum.ansible.com/t/playbook-includes-and-tags/17060/1 "2014-12-15T12:07:44Z")

</div>

I’m trying to add tags to tasks via includes but it doesn’t work as I expect. I have

$ cat site.yml  
#- { include: foo.yml, tags: [foo] }

- include: foo.yml tags=foo

$ cat foo.yml

- hosts: all  
tasks:
- name: foo  
debug: msg=foo

Then

$ ansible-playbook -i inventory site.yml -t foo  
ERROR: tag(s) not found in playbook: foo. possible values:

Same error with 1.8.2 and current devel branch and with the other include syntax commented above.

Any help much appreciated,

Adam

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [December 15, 2014, 1:24pm UTC](https://forum.ansible.com/t/playbook-includes-and-tags/17060/2 "2014-12-15T13:24:47Z")

</div>

Hi Adam,

This looks like it’s because you can add tags when pulling in roles, as well as tasks, but you can’t tag a playbook on an include.

It’s something that sounds reasonable, but probably not something that has been done before.

Try this:

- hosts: all  
tasks:
- include: my\_tasks.yml tags=foo

Etc

And should be good to go.

Alternatively:

roles:

- { name: foo, tags: [‘foo’, ‘bar’] }

etc

---

<div class="post-metadata">

**Author:** ![Adam\_Guthrie](https://avatars.discourse-cdn.com/v4/letter/a/f19dbf/32.png) [@Adam\_Guthrie](https://forum.ansible.com/u/Adam_Guthrie)\
**Post date:** [December 15, 2014, 2:06pm UTC](https://forum.ansible.com/t/playbook-includes-and-tags/17060/3 "2014-12-15T14:06:28Z")

</div>

Yeah, I guess I misunderstood the docs ([http://docs.ansible.com/playbooks\_tags.html](http://docs.ansible.com/playbooks_tags.html)) here.

Would you be open to a pull request to implement this?

Adam

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [December 15, 2014, 2:42pm UTC](https://forum.ansible.com/t/playbook-includes-and-tags/17060/4 "2014-12-15T14:42:37Z")

</div>

Tenatively, yes, I don’t see a problem with it applying to all the tasks/roles if done simply enough.

However given the ongoing v2 refactoring we should probably wait until this is complete. This should be in 1.9 (current release) timeframe.
