Add systemd role for restarting multiple services in same transaction
This commit is contained in:
9
roles/systemd/README.md
Normal file
9
roles/systemd/README.md
Normal file
@@ -0,0 +1,9 @@
|
||||
Adds systemd-related notifiable handlers
|
||||
|
||||
- Reload systemd daemon
|
||||
- Reloads all systemd unit files
|
||||
- Apply systemd unit restarts
|
||||
- Restarts multiple systemd units in a single transaction
|
||||
- Units to be restarted are defined in the `systemd_restart_units` variable of type list
|
||||
- The variable should be set using `ansible.builtin.set_fact`
|
||||
- The list must not be overridden, but appended (`systemd_restart_units: "{{ systemd_restart_units + ['restartme.service'] }}"`
|
||||
2
roles/systemd/defaults/main.yaml
Normal file
2
roles/systemd/defaults/main.yaml
Normal file
@@ -0,0 +1,2 @@
|
||||
---
|
||||
systemd_restart_units: []
|
||||
14
roles/systemd/handlers/main.yaml
Normal file
14
roles/systemd/handlers/main.yaml
Normal file
@@ -0,0 +1,14 @@
|
||||
---
|
||||
- name: Reload systemd daemon
|
||||
ansible.builtin.systemd_service:
|
||||
daemon_reload: true
|
||||
|
||||
- name: Apply systemd unit restarts # noqa: command-instead-of-module
|
||||
ansible.builtin.command:
|
||||
cmd: systemctl restart {{ systemd_restart_units | join(' ') }}
|
||||
changed_when: true
|
||||
|
||||
- name: Reset systemd restart units
|
||||
listen: Apply systemd units restart
|
||||
ansible.builtin.set_fact:
|
||||
systemd_restart_units: []
|
||||
Reference in New Issue
Block a user