Skip to content

Commit 722414a

Browse files
authored
Avoid starting the service twice (#123)
Only enable service in the main task and let the handler start it Skip reloading systemd and enable if unit file did not change The solution is for systemd only Fixes #118
1 parent 33888c2 commit 722414a

File tree

1 file changed

+19
-12
lines changed

1 file changed

+19
-12
lines changed

tasks/main.yml

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -179,22 +179,29 @@
179179
- not ansible_os_family == "Solaris"
180180
tags: skip_ansible_lint
181181

182-
- name: systemd script
183-
template:
184-
src: nomad_systemd.service.j2
185-
dest: /lib/systemd/system/nomad.service
186-
owner: root
187-
group: root
188-
mode: 0644
189-
when: ansible_service_mgr == "systemd"
190-
191-
- name: reload systemd daemon
192-
systemd:
193-
daemon_reload: true
182+
- block:
183+
- name: systemd script
184+
template:
185+
src: nomad_systemd.service.j2
186+
dest: /lib/systemd/system/nomad.service
187+
owner: root
188+
group: root
189+
mode: 0644
190+
register: nomad_systemd_file
191+
- block:
192+
- name: reload systemd daemon
193+
systemd:
194+
daemon_reload: true
195+
- name: Enable nomad at startup (systemd)
196+
systemd:
197+
name: nomad
198+
enabled: yes
199+
when: nomad_systemd_file.changed
194200
when: ansible_service_mgr == "systemd"
195201

196202
- name: Start Nomad
197203
service:
198204
name: nomad
199205
enabled: true
200206
state: started
207+
when: not ansible_service_mgr == "systemd"

0 commit comments

Comments
 (0)