|
@@ -0,0 +1,29 @@
|
|
|
+- name: 'configure systemd unit {{ systemd_unit_name }}'
|
|
|
+ copy:
|
|
|
+ dest: '/etc/systemd/system/{{ systemd_unit_name }}'
|
|
|
+ content: |
|
|
|
+ # ansible managed
|
|
|
+ {{ systemd_unit_config }}
|
|
|
+ mode: a=r
|
|
|
+ register: _config_file
|
|
|
+- name: 'fetch state of systemd unit {{ systemd_unit_name }}'
|
|
|
+ systemd:
|
|
|
+ name: '{{ systemd_unit_name }}'
|
|
|
+ register: _unit
|
|
|
+ when: _config_file.changed
|
|
|
+- name: 'set state of systemd unit {{ systemd_unit_name }}'
|
|
|
+ systemd:
|
|
|
+ daemon_reload: '{{ _config_file.changed }}'
|
|
|
+ name: '{{ systemd_unit_name }}'
|
|
|
+ enabled: '{{ systemd_unit_enabled | default(omit) }}'
|
|
|
+ state: >-
|
|
|
+ {{ "restarted" if (systemd_unit_state is not defined
|
|
|
+ or systemd_unit_state != "stopped")
|
|
|
+ and _config_file.changed
|
|
|
+ and _unit.status.ActiveState == "active"
|
|
|
+ else systemd_unit_state | default(omit) }}
|
|
|
+ when: >-
|
|
|
+ _config_file.changed
|
|
|
+ or systemd_unit_enabled is defined
|
|
|
+ or systemd_unit_state is defined
|
|
|
+ or (_config_file.changed and systemd_unit.status.ActiveState == "active")
|