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

**URL:** <https://forum.ansible.com/t/how-to-make-use-of-provided-tags-with-skip-tags-or-tags-inside-a-role-task/16191>\
**Category:** Ansible Project\
**Created:** [September 12, 2014, 9:54am UTC](https://forum.ansible.com/t/how-to-make-use-of-provided-tags-with-skip-tags-or-tags-inside-a-role-task/16191 "2014-09-12T09:54:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nicolai\_Froehlich](https://avatars.discourse-cdn.com/v4/letter/n/65b543/32.png) [@Nicolai\_Froehlich](https://forum.ansible.com/u/Nicolai_Froehlich)\
**Post date:** [September 12, 2014, 9:54am UTC](https://forum.ansible.com/t/how-to-make-use-of-provided-tags-with-skip-tags-or-tags-inside-a-role-task/16191/1 "2014-09-12T09:54:02Z")

</div>

---- 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](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.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [September 12, 2014, 1:52pm UTC](https://forum.ansible.com/t/how-to-make-use-of-provided-tags-with-skip-tags-or-tags-inside-a-role-task/16191/2 "2014-09-12T13:52:43Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Nicolai\_Froehlich](https://avatars.discourse-cdn.com/v4/letter/n/65b543/32.png) [@Nicolai\_Froehlich](https://forum.ansible.com/u/Nicolai_Froehlich)\
**Post date:** [September 15, 2014, 2:24pm UTC](https://forum.ansible.com/t/how-to-make-use-of-provided-tags-with-skip-tags-or-tags-inside-a-role-task/16191/3 "2014-09-15T14:24:58Z")

</div>

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](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 --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?
