# When to call a specific task from a role?

**URL:** <https://forum.ansible.com/t/when-to-call-a-specific-task-from-a-role/20866>\
**Category:** Ansible Project\
**Tags:** galaxy-ng\
**Created:** [March 14, 2016, 8:24pm UTC](https://forum.ansible.com/t/when-to-call-a-specific-task-from-a-role/20866 "2016-03-14T20:24:55Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gilberto\_Valentin](https://avatars.discourse-cdn.com/v4/letter/g/b4bc9f/32.png) [@Gilberto\_Valentin](https://forum.ansible.com/u/Gilberto_Valentin)\
**Post date:** [March 14, 2016, 8:24pm UTC](https://forum.ansible.com/t/when-to-call-a-specific-task-from-a-role/20866/1 "2016-03-14T20:24:55Z")

</div>

I am creating a role with **ansible-galaxy init role\_name**. One of the tasks in that role will be to install\_app.yml and another to remove\_app.yml (one to install and one to remove). Is it possible to call one task vs the other within that role or do I need to create a whole new role for that specific task?

---

<div class="post-metadata">

**Author:** ![Timothy\_Appnel1](https://avatars.discourse-cdn.com/v4/letter/t/278dde/32.png) [@Timothy\_Appnel1](https://forum.ansible.com/u/Timothy_Appnel1)\
**Post date:** [March 14, 2016, 9:30pm UTC](https://forum.ansible.com/t/when-to-call-a-specific-task-from-a-role/20866/2 "2016-03-14T21:30:52Z")

</div>

This is a question I’ve pondered in my own work. There is no one specific or recommended way Ansible prescribes for doing this. What follows are my own personal thoughts and mine alone.

You can do separate role as you suggest. Not ideal because it puts to much distance between closely related functionality for my liking.

You could tag tasks one or the other – however you must remember to pass a tag. No sure this is practical in that it’s too easy to mess up.

You can implement something with some combinations of params/variables, conditionals, includes and/or blocks. This is one I think has the most promise though the number of ways this could be implemented are pretty extensive in number.

---

<div class="post-metadata">

**Author:** ![Gilberto\_Valentin](https://avatars.discourse-cdn.com/v4/letter/g/b4bc9f/32.png) [@Gilberto\_Valentin](https://forum.ansible.com/u/Gilberto_Valentin)\
**Post date:** [March 15, 2016, 2:06pm UTC](https://forum.ansible.com/t/when-to-call-a-specific-task-from-a-role/20866/3 "2016-03-15T14:06:55Z")

</div>

Thanks for the input. I think I am going to start by creating two separate roles (one for install and one for removal). When I gain enough knowledge of Ansible, I’ll add some conditions within one role to execute one task vs the other.

---

<div class="post-metadata">

**Author:** ![Dick\_Davies](https://avatars.discourse-cdn.com/v4/letter/d/b9e5f3/32.png) [@Dick\_Davies](https://forum.ansible.com/u/Dick_Davies)\
**Post date:** [March 16, 2016, 2:05am UTC](https://forum.ansible.com/t/when-to-call-a-specific-task-from-a-role/20866/4 "2016-03-16T02:05:11Z")

</div>

I've done things like this before with some success:

playbook:$ cat roles/ci/tasks/main.yml
