1
votes

So i am having a structure like roles/base/tasks/main.yml & another file right above the roles/ directory with name base.yml which basically calls the base role. My problem is this, ansible docs suggest

roles:
  - { role: webserver, port: 5000, tags: [ 'web', 'foo' ] }

to call the main.yml if i have a tag defined as 'web'. I tried it but it didn't work & yes i saw a post on reddit too ---> https://www.reddit.com/r/ansible/comments/3628s8/question_about_using_tags_in_roles/

Soo is there a WAY to call tags defined in a role using .yml instead of the adhoc command , coz my deployment strategies don't allow me to run a adhoc command

1

1 Answers

1
votes

No, there is no way to specify the active tags other than invoking it from the command line with --tags.

Your example here:

roles:
  - { role: webserver, port: 5000, tags: [ 'web', 'foo' ] }

will actually tag every single task of the role webserver with the tags web and foo.

I think what you want instead is to only trigger the task within webserver which are tagged as web and/or foo. There's currently no built-in way.

There might be a solution, by creating a custom action plugin which injects tags into the runner object of Ansible. Action plugins are not documented at all and you will need to look at the source of some implemented actions. I once created an action plugin which interacts with the runner object, injecting variables. Tags might work in a similar way. If you follow this path, be aware that Ansible 2 will include big refactoring and I'm nearly sure plugins like this will break.