瀏覽代碼

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.
Christoph Schug 2 年之前
父節點
當前提交
7ceb755f35
共有 1 個文件被更改,包括 5 次插入1 次删除
  1. 5 1
      ansible/maintenance/maint-diskspace.yaml

+ 5 - 1
ansible/maintenance/maint-diskspace.yaml

@@ -4,7 +4,11 @@
 
 
   tasks:
   tasks:
     - name: Check disk space available
     - 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
       register: disk_usage
 
 
     # - name: Send discord message when disk space is over 80%
     # - name: Send discord message when disk space is over 80%