Skip to content

Commit 4121939

Browse files
committed
allow multiple persistent systemd services per role
1 parent 2f455b9 commit 4121939

File tree

2 files changed

+13
-15
lines changed

2 files changed

+13
-15
lines changed

ansible/roles/systemd/tasks/main.yml

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,32 @@
22
# NB: As `appliances_persistent_services` is defined in group_vars/all, all tasks here are conditional
33
- name: Make directory for unit dropins
44
file:
5-
path: "/etc/systemd/system/{{ item.value }}.service.d/"
5+
path: "/etc/systemd/system/{{ item.key }}.service.d/"
66
state: directory
77
loop: "{{ appliances_persistent_services | dict2items }}"
8-
when: "'item.key' in group_names"
8+
when: "'item.value' in group_names"
99

1010
- name: Add dropins for unit files
1111
ansible.builtin.copy:
1212
content: |
1313
[Unit]
1414
RequiresMountsFor={{ appliances_state_dir }}
15-
dest: "/etc/systemd/system/{{ item.value }}.service.d/appliance_state.conf"
15+
dest: "/etc/systemd/system/{{ item.key }}.service.d/appliance_state.conf"
1616
loop: "{{ appliances_persistent_service | dict2items }}"
17-
register: persistent_services_dropins
18-
when: "'item.key' in group_names"
17+
register: _systemd_persistent_services_dropins
18+
when: "'item.value' in group_names"
1919

2020
- name: Reload unit definitions
2121
ansible.builtin.shell:
2222
cmd: systemctl daemon-reload
23-
when:
24-
- persistent_services_dropins.changed
25-
- "'item.key' in group_names"
23+
when: _systemd_persistent_services_dropins.changed
2624

2725
- name: Reload units
2826
ansible.builtin.systemd:
29-
name: "{{ item.value }}"
27+
name: "{{ item.key }}"
3028
state: restarted
3129
loop: "{{ appliances_persistent_service | dict2items }}"
3230
when:
33-
- persistent_services_dropins.changed
34-
- "'item.key' in group_names"
31+
- _systemd_persistent_services_dropins.changed
32+
- "'item.value' in group_names"
3533
# - "'builder' not in group_names" # because mount of appliances_state_dir won't be done in builder

environments/common/inventory/group_vars/all/defaults.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ ansible_user: rocky
44
appliances_repository_root: "{{ lookup('env', 'APPLIANCES_REPO_ROOT') }}"
55
appliances_environment_root: "{{ lookup('env', 'APPLIANCES_ENVIRONMENT_ROOT') }}"
66
#appliances_state_dir: # define an absolute path here to use for persistent state
7-
appliances_persistent_services: # role: service requiring appliances_state_dir
7+
appliances_persistent_services: # dict of service:role requiring appliances_state_dir
88
# mysql not included as it role handles state dir correctly
99
opendistro: opendistro
10-
grafana: grafana-server
11-
openhpc: slurmdbd
12-
openhpc: slurmctld
10+
grafana-server: grafana
11+
slurmdbd: openhpc
12+
slurmctld: openhpc
1313
prometheus: prometheus
1414

1515
# Address(ip/dns) for internal communication between services. This is

0 commit comments

Comments
 (0)