Calling Tags From a Playbook

127 views
Skip to first unread message

Michael Liu

unread,
Jul 20, 2014, 6:06:45 AM7/20/14
to ansible...@googlegroups.com
I know you have to ability to call task tags from the command line, for example:

ansible-playbook -i staging_env mydeploy.yml --tags "web_stop"

But, is there a way to call task tags from with in a playbook?  I would rather create multiple playbooks such as web_start.yml, web_deploy.yml, stop_all.yml, start_all.yml and not have to worry about calling the appropriate tags at the command line.  My issue is that not everyone on the Ops team is as familiar with ansible (and all of the tags we use), so allowing them to just run "ansible-playbook -i staging_env start_all.yml" seems easier and safer.  And the goal is to keep my existing role/tasks structure without duplicating tasks between roles.  The main issue with the playbook is that when you apply a role to hosts it applies all of the tasks in that role, no way to pick and choose tasks in the playbook.

My dir structure for my web servers is as follows: 
    roles/web/tasks
        main.yml
        stop.yml
        update_code.yml
        start.yml
        check_service.yml

If it's not possible to call task tags from a playbook, is this something you're currently working?  Is there another way to achieve this?

Thanks so much for your time.

Michael DeHaan

unread,
Jul 20, 2014, 8:36:25 AM7/20/14
to ansible...@googlegroups.com
Basically this would be asking for a play level "use_tags" parameter.    (It would not be called "tags", as that would mean the existing ability *to tag*)

This is not something we are working on, but patches would be considered certaintly, the variable should only exist at play level (on level with "hosts:").




--
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/7e93c579-5ecc-426d-b168-728c06e946a7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Greg Swift

unread,
Jul 24, 2014, 10:36:55 AM7/24/14
to ansible...@googlegroups.com
So In my proposal you would specify use_tags (or whatever) when calling the role specifically, not at the play level.  If i'm bringing in multiple roles it seems like it would make sense to support it at the role level, or i guess maybe at both? Maybe I'm just over thinking it, but i can definitely see reasons why you would want to allow the more specific implementation. Seems like a anti-pattern to constantly add new plays just because a set of roles might share a tag yet you want one role to run tagA the other tagB, but they both have tagA.

Basically, what is the defining reason why this should be at the play level rather than in the call of the role?  I haven't looked at the code yet, so maybe its implementation?

-greg

Michael DeHaan

unread,
Jul 24, 2014, 6:45:05 PM7/24/14
to ansible...@googlegroups.com
Role and play level both would be acceptable, but I'd want it in both.

We'd need to find a nice way to work it into the docs on tags w/o making it too confusing.




Reply all
Reply to author
Forward
0 new messages