From 7ceb755f35c3bc73d497d3cc94267102521d79d8 Mon Sep 17 00:00:00 2001 From: Christoph Schug Date: Sun, 3 Mar 2024 17:49:31 +0100 Subject: [PATCH] fix: set `pipefail` flag in shell commands using pipes Without `pipefail` Ansible cannot detect if there is an error executing the command before the pipe as the return code of the shell only reflects the return code of the last command. As not all shells support `pipefail` (e.g., `ash`, `dash`) we also enfore the use of `bash` in this case. --- ansible/maintenance/maint-diskspace.yaml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ansible/maintenance/maint-diskspace.yaml b/ansible/maintenance/maint-diskspace.yaml index 677c02a..23f0386 100644 --- a/ansible/maintenance/maint-diskspace.yaml +++ b/ansible/maintenance/maint-diskspace.yaml @@ -4,7 +4,11 @@ tasks: - name: Check disk space available - ansible.builtin.shell: df -Ph / | awk 'NR==2 {print $5}' + ansible.builtin.shell: + cmd: | + set -euo pipefail + df -Ph / | awk 'NR==2 {print $5}' + executable: /bin/bash register: disk_usage # - name: Send discord message when disk space is over 80%