How to make use of provided tags with --skip-tags or --tags inside a (role)-task ?

51 views
Skip to first unread message

Nicolai Froehlich

unread,
Sep 12, 2014, 5:54:02 AM9/12/14
to ansible...@googlegroups.com
---- Question

Is it possible to access the list of provided tags ( --tags, --skip-tags ) from a variable inside a task?

Is it maybe possible to access the invoked command itself from variable?

Is it possible to use patterns (http://docs.ansible.com/intro_patterns.html) with tags? 
Something like --tags=config,&reload would be very helpful.

------ Example

Given i have:

- task A with tags: [ config ] 
- task B with tags: [ config, reload ] 
- task C with tags: [ service, reload ]

---- Problem

I'd like to skip task B if --tags does not contain 'config' AND 'reload'.

Thanks in advance.






Michael DeHaan

unread,
Sep 12, 2014, 9:53:03 AM9/12/14
to ansible...@googlegroups.com
No, this is not available, it doesn't really make sense for a task to know what tags are available because it can't do anything with that information.

Boolean operations other than "OR" on --tags is also not presently available.




--
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/5c9e5307-59b7-4b30-b366-3b279cecdd4c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Nicolai Froehlich

unread,
Sep 15, 2014, 10:24:58 AM9/15/14
to ansible...@googlegroups.com
Hello Michal,

thanks for your time & answer. I was asking because i wanted to extend the use of host(-group) patterns (http://docs.ansible.com/intro_patterns.html)... to tags.

It would allow for generic roles to provide tasks that don't get executed by default ... but can be triggered by providing a certain set of tags.

Imagine it was possible to do the following ...

ansible <playbook> --tags php-fpm,nginx,&service,&stop

which would match all tasks with exacly

- tags: [php-fpm, service, stop]
- tags: [nginx, service, stop]

... to stop the php-fpm and nginx service. 

I can imagine a lot of use-cases where this would come in handy. 

The idea came up while i was developing a "dashboard" for my development machine that would allow me to quickly change it's state by selecting tags (using autocompletion).

How cool would it be to just ... click together some expressive commands like "composer, install" , "mysql, install" ... and have the machine in the desired state.
 
It shouldn't be too hard to expose the provided tags as a variable + create a jinja function that can be used inside 'when' and evaluates the provided tags against the 'tags' variable ? 

What are your thoughts about this? Could you share some implementation tips or am I on the completely wrong track here?
Reply all
Reply to author
Forward
0 new messages