# Selectively execute tasks in an ansible role based on tags

**URL:** <https://forum.ansible.com/t/selectively-execute-tasks-in-an-ansible-role-based-on-tags/43075>\
**Category:** Get Help\
**Tags:** aap\
**Created:** [May 29, 2025, 10:06pm UTC](https://forum.ansible.com/t/selectively-execute-tasks-in-an-ansible-role-based-on-tags/43075 "2025-05-29T22:06:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![carlyle705](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/carlyle705/32/5552_2.png) [@carlyle705](https://forum.ansible.com/u/carlyle705)\
**Post date:** [May 29, 2025, 10:06pm UTC](https://forum.ansible.com/t/selectively-execute-tasks-in-an-ansible-role-based-on-tags/43075/1 "2025-05-29T22:06:48Z")

</div>

Folks, need some help on this.  
I have an existing ansible role which includes some tasks. Each task has a tag, some of them are tagged as "tag1’ and the others are tagged as “tag2”.  
I want to include this role from another role and execute the tasks only tagged as “tag1”.

Note: I’m running the template through AAP 2.4 web interface and I don’t have access to the ansible command line.

How to achieve this?

---

<div class="post-metadata">

**Author:** ![jiholland](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jiholland/32/11273_2.png) [@jiholland](https://forum.ansible.com/u/jiholland)\
**Post date:** [May 30, 2025, 8:48am UTC](https://forum.ansible.com/t/selectively-execute-tasks-in-an-ansible-role-based-on-tags/43075/2 "2025-05-30T08:48:17Z")

</div>

> **[Chapter 20. Job templates | Automation controller user guide | Red...](https://docs.redhat.com/en/documentation/red_hat_ansible_automation_platform/2.4/html/automation_controller_user_guide/controller-job-templates)**
>
> Chapter 20. Job templates | Automation controller user guide | Red Hat Ansible Automation Platform | 2.4 | Red Hat Documentation

There is a field called Job Tags for Job Templates (playbooks) in AAP which I belive does what you are asking.

---

<div class="post-metadata">

**Author:** ![bcoca](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/bcoca/32/9269_2.png) [@bcoca](https://forum.ansible.com/u/bcoca)\
**Post date:** [May 30, 2025, 2:26pm UTC](https://forum.ansible.com/t/selectively-execute-tasks-in-an-ansible-role-based-on-tags/43075/3 "2025-05-30T14:26:28Z")

</div>

Tag selection cannot be done ‘in play’, only when calling it, I recommend for ‘in play selection’ to use different task files and the `tasks_from` parameter from `include_role`/`import_role`.

---

<div class="post-metadata">

**Author:** ![utoddl](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/utoddl/32/249_2.png) [@utoddl](https://forum.ansible.com/u/utoddl)\
**Post date:** [May 30, 2025, 4:25pm UTC](https://forum.ansible.com/t/selectively-execute-tasks-in-an-ansible-role-based-on-tags/43075/4 "2025-05-30T16:25:12Z")

</div>

I’d go a step farther than that, and say generally the simpler you can keep your tags the better. Or rather, how you use tags in a given project. If you can clearly say, “Within the project, we use tags in this one way” then you might not go nuts. But start mixing different tag usage techniques at your own risk.

Also, I agree with @bcoca 's prior comment; that’s the way to do things, _generally_.

However, In this (one, special) case, assuming you **aren’t already using tags in other ways** in the project, you could consider using `--skip-tags=tag2` when you only want to run only the `tag1` tasks, and `--skip-tags=tag1` when you only want to run the `tag2` tasks. If you do this, consider it a temporary measure while you work out more general tagging techniques.
