From 28ab754a30c71f84b2ca1b0acd6cf8449dbaf1f3 Mon Sep 17 00:00:00 2001
From: ale <ale@incal.net>
Date: Wed, 31 Mar 2021 12:16:57 +0100
Subject: [PATCH] Do not run systemctl commands without arguments

And use try-reload-or-restart, to be more amenable to failures.
---
 roles/float-util-credentials/tasks/main.yml | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/roles/float-util-credentials/tasks/main.yml b/roles/float-util-credentials/tasks/main.yml
index dcf4ce4f..9d202eb9 100644
--- a/roles/float-util-credentials/tasks/main.yml
+++ b/roles/float-util-credentials/tasks/main.yml
@@ -103,8 +103,8 @@
 
     # This should use the systemd module but it doesn't take lists of services.
     - name: "Restart associated services"
-      shell: "systemctl restart {{ all_systemd_units.stdout_lines | intersect(services[item.0.service].systemd_services) | join(' ') }}"
-      when: "item.1.changed and item.0.service != 'LOCAL' and services[item.0.service].systemd_services"
+      shell: "systemctl try-reload-or-restart {{ all_systemd_units.stdout_lines | intersect(services[item.0.service].systemd_services) | join(' ') }}"
+      when: "item.1.changed and item.0.service != 'LOCAL' and (all_systemd_units.stdout_lines | intersect(services[item.0.service].systemd_services))"
       loop: "{{ credentials | zip(x509_sign.results) | list }}"
 
   rescue:
-- 
GitLab