This might be more of a design question than a syntax question. I have a set of Ansible playbooks responsible for setting up various systemd services to configure a server a particular way. I'm sure this is a very typical usecase. However, my question is: what is the best way to shutdown and disable services before continuing with the installation and configuration? Here are my requirements:
- Should be able to just shutdown and disable services across a set of servers without then running the installation
- Should also be able to shutdown/disable and then proceed with the installation
- If we are running a shutdown followed by an install, all non-dedicated hosts should be cleaned and the dedicated host group should be chosen for install
For example, let's say I have 3 servers: A, B, C and I have 2 services to install and configure: httpd and nginx. My hosts file looks like this:
[apache]
A
C
[nginx]
B
The end result should have httpd running on servers A and C (and shutdown/disabled on B), with Nginx running on B (and shutdown/disabled on A and C).
My inital thoughts on possible solutions to this are:
- Create separate playbooks for running each uninstall (because I already have playbooks for installation) (This might be correct, but certainly a lot of code duplication and more work)
- Create some additional task that sits alongside the main.yml file in the existing installation roles (Is this possible? This feels right if so.)
- A master uninstall playbook that can be invoked directly before running any install playbooks. (This feels wrong)