How to only play tasks with specific tags in playbook

83 views
Skip to first unread message

Brendon Standing

unread,
Jul 11, 2014, 10:58:30 AM7/11/14
to ansible...@googlegroups.com
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

Michael DeHaan

unread,
Jul 11, 2014, 6:30:57 PM7/11/14
to ansible...@googlegroups.com
Pass the "--tags" option to ansible-playbook to run only the tags you want to run.




--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/e064ad14-538d-4c7c-aae7-3a7c43fcfac6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Michael DeHaan

unread,
Jul 11, 2014, 6:31:20 PM7/11/14
to ansible...@googlegroups.com
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.

Brendon Standing

unread,
Jul 17, 2014, 2:31:40 PM7/17/14
to ansible...@googlegroups.com
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.

Michael DeHaan

unread,
Jul 17, 2014, 9:39:13 PM7/17/14
to ansible...@googlegroups.com
"Surely a playbook by design should be a playbook?"

All ducks must quack, except when they are elephants.



Brendon Standing

unread,
Jul 18, 2014, 9:07:52 AM7/18/14
to ansible...@googlegroups.com
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.

Michael DeHaan

unread,
Jul 18, 2014, 2:06:41 PM7/18/14
to ansible...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages