From 36c12a330f6ffe10e2ff1d0ad1cb486b874e0a1b Mon Sep 17 00:00:00 2001 From: Tobias Reisinger Date: Fri, 18 Oct 2024 14:32:30 +0200 Subject: [PATCH] Fix shell_module executable and mail healthcheck --- playbooks/roles/healthcheck/files/data/mail | 24 ++++++++++++++----- playbooks/roles/healthcheck/tasks/systemd.yml | 1 + playbooks/roles/lego/tasks/systemd.yml | 1 + playbooks/roles/software/tasks/main.yml | 6 ++--- 4 files changed, 23 insertions(+), 9 deletions(-) diff --git a/playbooks/roles/healthcheck/files/data/mail b/playbooks/roles/healthcheck/files/data/mail index 650815d..d048950 100755 --- a/playbooks/roles/healthcheck/files/data/mail +++ b/playbooks/roles/healthcheck/files/data/mail @@ -9,9 +9,21 @@ alias curl_hc='curl -LA "$USER_AGENT" --retry 3' envsubst < template.msmtprc > /tmp/msmtprc envsubst < mailcheck.template.mail > /tmp/mailcheck.mail -result=$(msmtp -C /tmp/msmtprc -a default "$MAIL_HC_UID@hc-ping.com" < /tmp/mailcheck.mail 2>&1) -if [ "$?" != "0" ] -then - echo "$result" - curl_hc --data-raw "$result" "$hc_url/fail" >/dev/null -fi +# Retry 3 times +for i in 1 2 3 +do + result=$(msmtp -C /tmp/msmtprc -a default "$MAIL_HC_UID@hc-ping.com" < /tmp/mailcheck.mail 2>&1) + if [ "$?" = "0" ] + then + exit 0 + fi + + if [ $i -eq 3 ] + then + echo "$result" + curl_hc --data-raw "$result" "$hc_url/fail" >/dev/null + exit 1 + fi + + sleep 3 +done diff --git a/playbooks/roles/healthcheck/tasks/systemd.yml b/playbooks/roles/healthcheck/tasks/systemd.yml index d9def2d..72eac1c 100644 --- a/playbooks/roles/healthcheck/tasks/systemd.yml +++ b/playbooks/roles/healthcheck/tasks/systemd.yml @@ -14,6 +14,7 @@ - name: Get all healthcheck timers ansible.builtin.shell: # noqa: command-instead-of-module + executable: /usr/bin/bash cmd: "set -o pipefail && systemctl list-timers 'healthcheck@*' --all --output=json | jq -r '.[].unit'" register: systemd_timers_result changed_when: false diff --git a/playbooks/roles/lego/tasks/systemd.yml b/playbooks/roles/lego/tasks/systemd.yml index e8c2a17..67dd1b1 100644 --- a/playbooks/roles/lego/tasks/systemd.yml +++ b/playbooks/roles/lego/tasks/systemd.yml @@ -14,6 +14,7 @@ - name: Get all lego timers ansible.builtin.shell: + executable: /usr/bin/bash cmd: "set -o pipefail && systemctl list-timers 'lego@*' --all --output=json | jq -r '.[].unit'" register: systemd_timers_result changed_when: false diff --git a/playbooks/roles/software/tasks/main.yml b/playbooks/roles/software/tasks/main.yml index 9d3cf35..a8db4c9 100644 --- a/playbooks/roles/software/tasks/main.yml +++ b/playbooks/roles/software/tasks/main.yml @@ -23,9 +23,9 @@ register: autorestic_status - name: Install autorestic - ansible.builtin.shell: set -o pipefail && wget -qO - https://raw.githubusercontent.com/cupcakearmy/autorestic/master/install.sh | bash - args: - executable: /bin/bash + ansible.builtin.shell: + executable: /usr/bin/bash + cmd: set -o pipefail && wget -qO - https://raw.githubusercontent.com/cupcakearmy/autorestic/master/install.sh | bash when: not autorestic_status.stat.exists changed_when: true become: true