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

**URL:** <https://forum.ansible.com/t/is-there-a-way-to-run-tasks-that-have-all-of-the-tasks-given-as-parameters-to-ansible-playbook/25724>\
**Category:** Ansible Project\
**Created:** [October 12, 2017, 1:04am UTC](https://forum.ansible.com/t/is-there-a-way-to-run-tasks-that-have-all-of-the-tasks-given-as-parameters-to-ansible-playbook/25724 "2017-10-12T01:04:20Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Behrang](https://avatars.discourse-cdn.com/v4/letter/b/ed655f/32.png) [@Behrang](https://forum.ansible.com/u/Behrang)\
**Post date:** [October 12, 2017, 1:04am UTC](https://forum.ansible.com/t/is-there-a-way-to-run-tasks-that-have-all-of-the-tasks-given-as-parameters-to-ansible-playbook/25724/1 "2017-10-12T01:04:20Z")

</div>

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**?

---

<div class="post-metadata">

**Author:** ![doug](https://avatars.discourse-cdn.com/v4/letter/d/dbc845/32.png) [@doug](https://forum.ansible.com/u/doug)\
**Post date:** [October 12, 2017, 3:24am UTC](https://forum.ansible.com/t/is-there-a-way-to-run-tasks-that-have-all-of-the-tasks-given-as-parameters-to-ansible-playbook/25724/2 "2017-10-12T03:24:13Z")

</div>

Good question

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

---

<div class="post-metadata">

**Author:** ![alanpassel7](https://avatars.discourse-cdn.com/v4/letter/a/848f3c/32.png) [@alanpassel7](https://forum.ansible.com/u/alanpassel7)\
**Post date:** [October 12, 2017, 4:12am UTC](https://forum.ansible.com/t/is-there-a-way-to-run-tasks-that-have-all-of-the-tasks-given-as-parameters-to-ansible-playbook/25724/3 "2017-10-12T04:12:52Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Behrang](https://avatars.discourse-cdn.com/v4/letter/b/ed655f/32.png) [@Behrang](https://forum.ansible.com/u/Behrang)\
**Post date:** [October 12, 2017, 5:41am UTC](https://forum.ansible.com/t/is-there-a-way-to-run-tasks-that-have-all-of-the-tasks-given-as-parameters-to-ansible-playbook/25724/4 "2017-10-12T05:41:50Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [October 12, 2017, 7:55am UTC](https://forum.ansible.com/t/is-there-a-way-to-run-tasks-that-have-all-of-the-tasks-given-as-parameters-to-ansible-playbook/25724/5 "2017-10-12T07:55:43Z")

</div>

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.
