aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2023-08-23 18:35:25 +0200
committerEgor Tensin <Egor.Tensin@gmail.com>2023-08-23 18:57:52 +0200
commitaeb8685d4861c6da1f5bd444c7a1ab4ba96a2f24 (patch)
tree81ec67d9ddff134d9e11b2c669db503251816ca5
parentadd role systemd_depend_iface (diff)
downloadinfra-ansible-aeb8685d4861c6da1f5bd444c7a1ab4ba96a2f24.tar.gz
infra-ansible-aeb8685d4861c6da1f5bd444c7a1ab4ba96a2f24.zip
systemd_depend_*: don't restart missing services
-rw-r--r--roles/systemd_depend_iface/handlers/main.yml11
-rw-r--r--roles/systemd_depend_iface/handlers/service.yml6
-rw-r--r--roles/systemd_depend_mount/handlers/main.yml11
-rw-r--r--roles/systemd_depend_mount/handlers/service.yml6
4 files changed, 26 insertions, 8 deletions
diff --git a/roles/systemd_depend_iface/handlers/main.yml b/roles/systemd_depend_iface/handlers/main.yml
index 2782200..813a651 100644
--- a/roles/systemd_depend_iface/handlers/main.yml
+++ b/roles/systemd_depend_iface/handlers/main.yml
@@ -4,10 +4,13 @@
daemon_reload: true
listen: systemd_depend_iface_restart
+- name: Collect installed services
+ ansible.builtin.service_facts:
+ listen: systemd_depend_iface_restart
+
- name: Restart systemd services
- become: true
- ansible.builtin.systemd_service:
- name: '{{ item }}'
- state: restarted
+ ansible.builtin.include_tasks: service.yml
listen: systemd_depend_iface_restart
loop: "{{ systemd_depend_iface_result.results | selectattr('changed', 'equalto', true) | map(attribute='service') | list }}"
+ loop_control:
+ loop_var: service
diff --git a/roles/systemd_depend_iface/handlers/service.yml b/roles/systemd_depend_iface/handlers/service.yml
new file mode 100644
index 0000000..10ead91
--- /dev/null
+++ b/roles/systemd_depend_iface/handlers/service.yml
@@ -0,0 +1,6 @@
+- name: 'Restart {{ service }}'
+ become: true
+ ansible.builtin.systemd_service:
+ name: '{{ service }}'
+ state: restarted
+ when: service in ansible_facts.services
diff --git a/roles/systemd_depend_mount/handlers/main.yml b/roles/systemd_depend_mount/handlers/main.yml
index 81bae32..207c203 100644
--- a/roles/systemd_depend_mount/handlers/main.yml
+++ b/roles/systemd_depend_mount/handlers/main.yml
@@ -4,10 +4,13 @@
daemon_reload: true
listen: systemd_depend_mount_restart
+- name: Collect installed services
+ ansible.builtin.service_facts:
+ listen: systemd_depend_mount_restart
+
- name: Restart systemd services
- become: true
- ansible.builtin.systemd_service:
- name: '{{ item }}'
- state: restarted
+ ansible.builtin.include_tasks: service.yml
listen: systemd_depend_mount_restart
loop: "{{ systemd_depend_mount_result.results | selectattr('changed', 'equalto', true) | map(attribute='service') | list }}"
+ loop_control:
+ loop_var: service
diff --git a/roles/systemd_depend_mount/handlers/service.yml b/roles/systemd_depend_mount/handlers/service.yml
new file mode 100644
index 0000000..10ead91
--- /dev/null
+++ b/roles/systemd_depend_mount/handlers/service.yml
@@ -0,0 +1,6 @@
+- name: 'Restart {{ service }}'
+ become: true
+ ansible.builtin.systemd_service:
+ name: '{{ service }}'
+ state: restarted
+ when: service in ansible_facts.services