Hi all, I have a strange one that I hope you can help me with.
I’m trying to make a role for systemd service unit files. This is the newfangled replacement for good ol’ sysV init scripts in Rhel7, any recent Fedora and a lot of other linux distros.
The workflow is supposed to go something like this.
- edit/install a unit file, like /etc/systemd/system/myservice.service
- run systemctl daemon-reload
- run systemctl enable myservice
- run systemctl start myservice
daemon-reload tells the systemd daemon to re-read the unit files so it will know you changed something
In ansible, I interpret that as looking like
- template out unit file
- notify daemon-reload handler if unit file changed
- service enable=true state=started name=myservice
The problem is, if I’ve changed the unit file, the daemon-reload runs after the service enable/start, so systemd doesn’t know to re-read the unit file before trying to start/enable the service.
I could just make it run daemon-reload every time the role runs, which kindof sucks. Also, if I’m installing a boatload of unit files, I’d like to do a daemon-reload only once to get them all. I could make the daemon-reload a normal task that only runs when the template changes, but that means I’d be running the daemon-reload once for every unit file, which sucks in the case where I’m installing a boatload of them. I looked at post_task, but that’s not for roles.
Does anyone know a good way to do this?
Thanks!
-Dylan