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.
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:”).
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
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.