Yeah, I agree. I’m finding the use case for uninstalling software to be rare and much harder than just building a new machine from scratch.
I am finding, though, that it would be helpful to be able to choose what tags to be run or skipped for a role, though, by specifying it when writing a playbook, rather than via the command line.
For instance, I could write a role for a piece of software that allows it to be installed for apache or nginx. The different configs should be with the role, but at playbook writing time, it would be very useful to be able to choose what tagged tasks to run for that group of hosts. For instance:
— inventory.ini —
[groupA]
apache01
apache02
[groupN]
nginx01
nginx02
— deploy_mysoftware.yml —
-
hosts: groupA
roles:
-
{ role: mysoftware, run_tasks: install,config_apache }
-
{ role: apache, run_tasks: restart_service }
-
hosts: groupN
roles:
-
{ role: mysoftware, run_tasks: install,config_nginx }
-
{ role: nginx, run_tasks: restart_service }
With this playbook, I could easy write ansible-playbook deploy_mysoftware.yml -i myinventory to deploy my software and restart the appropriate services depending on the server group. This is nice and compact. In addition, if something gets changed in the software’s interaction with the webserver software, I can just update the mysoftware role config templates and everything is good. This allows roles to be more rich in the set of tasks they need to accomplish, yet gives the flexibility to run only a portion of those tasks.
I think one solution would be probably to create a mysoftware role, plus a mysoftware_nginx and mysoftware_apache role, which then begins to disassociate code and configs that should probably be more closely coupled together. Also the restarting of the service task could not be singled out from the installation of it. I think one would probably have to create a separate role for just restarting the service, or would have to duplicate those tasks across playbooks.
An alternate solution would be to pass --tags and --skip-tags via the command line, but then I have to make sure I don’t accidentally mistype something, or I write a two liner script that just calls ansible-playbook with the right arguments (requiring yet another file). That wouldn’t solve the problem, though, if two roles end up using the same tags, such as ‘install’, which is very common. The playbook without run_tasks would be:
— deploy_mysoftware.yml —
-
hosts: groupA
roles:
-
{ role: mysoftware }
-
{ role: apache }
-
hosts: groupN
roles:
-
{ role: mysoftware }
-
{ role: nginx }
In the above example, I wouldn’t be able to write ansible-playbook deploy_mysoftware.yml -i myinventory --tags=install,config_apache,config_nginx,restart_service because the config_apache,config_nginx would end up getting applied to both groupA and groupN and install would get applied to apache and nginx, which is not the desired outcome of that particular playbook.
Thanks,
Trevor