From 52a96f9bdea218525a188d6a679ccde4b1fc5f48 Mon Sep 17 00:00:00 2001 From: simonspa <1677436+simonspa@users.noreply.github.com> Date: Tue, 27 Jul 2021 16:55:03 +0200 Subject: [PATCH] Check for systemd list-unit-files before restarting services Co-authored-by: Karl M. Davis --- defaults/main.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/defaults/main.yml b/defaults/main.yml index 20a3a0a..a194816 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -60,4 +60,9 @@ certbot_keep_updated: true certbot_dir: /opt/certbot # Restart this service after successfull certificate creation: -certbot_deployhook: "service {{ certbot_create_standalone_stop_services | join(' restart && service ') }} restart" +certbot_deployhook: | + {% for service in certbot_create_standalone_stop_services %} + if systemctl list-unit-files | grep -q "^{{ service }}.service"; then + systemctl restart {{ service }} + fi + {% endfor %}