- name: Display any lines that have more FS usage than 80% shell: df -h | awk '$NF { print $1, $5 } $5+0 > 80' register: filesystem - debug: var: filesystem.stdout_lines - fail: msg: “Disk space is running low” when: filesystem.stdout | int > 80
I am expecting the playbook to fail for any lines that have more disk usage than 80%
you need to consider:
filesystem.stdout_lines
is a list with multiple values, this is different to the variable in the when
condition, which combines all those records as a single string value, that's why the comparison | int > 80
| int > 80
fails, so you will need to compare one row at a time
note that the record has the volume name and the disk, as the print
in awk
defines print $1, $5
, to do the when comparison you would need to split the value, from the disk utilization you would also need to remove the percentage character and convert the value to a number to make the comparison
you have 2 comparisons, one in the shell command with awk ( $5+0 > 80
) the result, in theory will only contains the volumes with higher disk utilization, so the when
in the fail wouldn't be necessary
- fail:
msg: “Disk space is running low in {{ item }}”
with_items: "{{ filesystem.stdout_lines }}"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.