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?
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.
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.
I've done things like this before with some success:
playbook:$ cat roles/ci/tasks/main.yml