Browse Source

add return value "systemd_unit_config_changed"

Fabian Peter Hammerle 1 year ago
parent
commit
653c36d030
2 changed files with 14 additions and 6 deletions
  1. 6 0
      README.md
  2. 8 6
      tasks/main.yml

+ 6 - 0
README.md

@@ -24,6 +24,12 @@ systemd_unit_enabled: yes
 systemd_unit_restart_if_active: no
 ```
 
+## Return Values
+
+```
+systemd_unit_config_changed
+```
+
 ## Limitations
 
 For `systemd_unit_scope != "system"` the following features are not yet supported:

+ 8 - 6
tasks/main.yml

@@ -29,15 +29,19 @@
     mode: a=r
   register: _dropin_config_file
   when: systemd_unit_dropin_config is defined
+- name: set return values
+  set_fact:
+    systemd_unit_config_changed: >-
+      {{ _config_file.changed or _dropin_config_file.changed }}
 - name: 'fetch state of systemd unit {{ systemd_unit_name }}'
   systemd:
     name: '{{ systemd_unit_name }}'
   register: _unit
   when: systemd_unit_scope == 'system'
-    and (_config_file.changed or _dropin_config_file.changed or systemd_unit_restart_if_active)
+    and (systemd_unit_config_changed or systemd_unit_restart_if_active)
 - name: 'set state of systemd unit {{ systemd_unit_name }}'
   systemd:
-    daemon_reload: '{{ _config_file.changed or _dropin_config_file.changed }}'
+    daemon_reload: '{{ systemd_unit_config_changed }}'
     name: '{{ systemd_unit_name }}'
     enabled: '{{ systemd_unit_enabled | default(omit) }}'
     # > `started'/`stopped' are idempotent actions [...]
@@ -45,16 +49,14 @@
     state: >-
       {{ "restarted" if (systemd_unit_state is not defined
                             or systemd_unit_state != "stopped")
-                         and (_config_file.changed
-                            or _dropin_config_file.changed
+                         and (systemd_unit_config_changed
                             or systemd_unit_restart_if_active)
                          and 'ActiveState' in _unit.status
                          and _unit.status.ActiveState == "active"
          else systemd_unit_state | default(omit) }}
   when: >-
     systemd_unit_scope == 'system'
-    and (_config_file.changed
-      or _dropin_config_file.changed
+    and (systemd_unit_config_changed
       or systemd_unit_enabled is defined
       or systemd_unit_state is defined
       or (systemd_unit_restart_if_active