# How to only play tasks with specific tags in playbook

**URL:** <https://forum.ansible.com/t/how-to-only-play-tasks-with-specific-tags-in-playbook/15651>\
**Category:** Ansible Project\
**Created:** [July 11, 2014, 2:58pm UTC](https://forum.ansible.com/t/how-to-only-play-tasks-with-specific-tags-in-playbook/15651 "2014-07-11T14:58:30Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Brendon\_Standing](https://avatars.discourse-cdn.com/v4/letter/b/e9a140/32.png) [@Brendon\_Standing](https://forum.ansible.com/u/Brendon_Standing)\
**Post date:** [July 11, 2014, 2:58pm UTC](https://forum.ansible.com/t/how-to-only-play-tasks-with-specific-tags-in-playbook/15651/1 "2014-07-11T14:58:30Z")

</div>

Hi all,

How do you play just the tasks with set tags in your playbook? From the command line you would do something like:  
ansible-playbook -i staging deploy.yml --tags “do\_stop, do\_health\_check”

I would expect do be able to do the same from the playbook like:

- hosts: somehosts  
roles:
- { role: connect, tags: [‘do\_stop’, ‘do\_health\_check’] }

However this is not working and it plays all the tasks in my role.

Regards,

Brendon

---

<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:** [July 11, 2014, 10:30pm UTC](https://forum.ansible.com/t/how-to-only-play-tasks-with-specific-tags-in-playbook/15651/2 "2014-07-11T22:30:52Z")

</div>

Pass the “–tags” option to ansible-playbook to run only the tags you want to run.

---

<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:** [July 11, 2014, 10:31pm UTC](https://forum.ansible.com/t/how-to-only-play-tasks-with-specific-tags-in-playbook/15651/3 "2014-07-11T22:31:16Z")

</div>

What you did above, BTW, is apply the tag “do\_stop” and “do\_health\_check” to every task in your role. This isn’t what you want, I’m guessing.

---

<div class="post-metadata">

**Author:** ![Brendon\_Standing](https://avatars.discourse-cdn.com/v4/letter/b/e9a140/32.png) [@Brendon\_Standing](https://forum.ansible.com/u/Brendon_Standing)\
**Post date:** [July 17, 2014, 6:31pm UTC](https://forum.ansible.com/t/how-to-only-play-tasks-with-specific-tags-in-playbook/15651/4 "2014-07-17T18:31:39Z")

</div>

Thanks all. I know that I can call tags from the command line and that my example will apply new tags in my playbook. But to me a playbook by design should be able to run all the tasks that you need to run by calling the tags you have set in tasks/\*.yml. Instead we are now presented with 2 options:

1. Write a wrapper script (oh no)
2. Further dismantle tasks into separate yml files so that you can call these with include in your playbook.

Surely a playbook by design should be a playbook?

Many thanks.

---

<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:** [July 18, 2014, 1:39am UTC](https://forum.ansible.com/t/how-to-only-play-tasks-with-specific-tags-in-playbook/15651/5 "2014-07-18T01:39:11Z")

</div>

“Surely a playbook by design should be a playbook?”

All ducks must quack, except when they are elephants.

---

<div class="post-metadata">

**Author:** ![Brendon\_Standing](https://avatars.discourse-cdn.com/v4/letter/b/e9a140/32.png) [@Brendon\_Standing](https://forum.ansible.com/u/Brendon_Standing)\
**Post date:** [July 18, 2014, 1:07pm UTC](https://forum.ansible.com/t/how-to-only-play-tasks-with-specific-tags-in-playbook/15651/6 "2014-07-18T13:07:52Z")

</div>

This is why I generally don’t join forums. Clearly your experience is limited to a small component stack and I should have gone with Chef.

---

<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:** [July 18, 2014, 6:06pm UTC](https://forum.ansible.com/t/how-to-only-play-tasks-with-specific-tags-in-playbook/15651/7 "2014-07-18T18:06:37Z")

</div>

Heh.
