Is there a way to run tasks that have ALL of the tasks given as parameters to ansible-playbook?

26 views
Skip to first unread message

Behrang Saeedzadeh

unread,
Oct 11, 2017, 9:04:20 PM10/11/17
to Ansible Project
For example, let's pretend we have these tasks:

- name: Task 1
  tags
:
   
- foo
   
- bar

- name: Task 2
  tags
:
   
- foo

- name: Task 3
  tags
:
   
- bar

Is there a way to only execute tasks that have both of foo and bar tags? That's, only execute Task 1?

Douglas Duckworth

unread,
Oct 11, 2017, 11:24:28 PM10/11/17
to ansible...@googlegroups.com
Good question

I have also wondered if you can run tasks with all tags.  Eg -t all.

--
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-project+unsubscribe@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/480774d6-2a14-4d18-8dff-a4e50617ab5d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

alanp...@gmail.com

unread,
Oct 12, 2017, 12:12:53 AM10/12/17
to Ansible Project
I don't think so. In this case, I would just give tasks that have both foo and bar as tags a third tag that will allow those tasks to be run. It's a little cumbersome, but it would work. However, as far as I know, there is no AND type of operator for tags.

Behrang Saeedzadeh

unread,
Oct 12, 2017, 1:41:50 AM10/12/17
to Ansible Project
> I would just give tasks that have both foo and bar as tags a third tag that will allow those tasks to be run

Unfortunately this won't work for me. I have multiple roles imported in my playbook:

    - { role: a, tags: ["a"] }
    - { role: b, tags: ["b"] }
    - { role: b, tags: ["c"] }
    - { role: c, tags: ["d"] }

So all tasks within role a inherit the tag a, the tasks within role b inherit the tag b, and so forth.

Inside these roles, some tasks are tagged with, say "x". I want to execute the "x" task in role "b".

Kai Stian Olstad

unread,
Oct 12, 2017, 3:56:04 AM10/12/17
to ansible...@googlegroups.com
On 12.10.2017 07:41, Behrang Saeedzadeh wrote:
>> I would just give tasks that have both foo and bar as tags a third tag
> that will allow those tasks to be run
>
> Unfortunately this won't work for me. I have multiple roles imported in
> my
> playbook:
>
> - { role: a, tags: ["a"] }
> - { role: b, tags: ["b"] }
> - { role: b, tags: ["c"] }
> - { role: c, tags: ["d"] }
>
> So all tasks within role a inherit the tag a, the tasks within role b
> inherit the tag b, and so forth.
>
> Inside these roles, some tasks are tagged with, say "x". I want to
> execute
> the "x" task in role "b".

You can achieve this by using when on the role to check a variable that
you provide with extra_vars on the command line and keep the tags in the
roles.

--
Kai Stian Olstad
Reply all
Reply to author
Forward
0 new messages