tasks:
- name: Disk usage from device
shell: df -h /dev/(device path) --output\=pcent | tail -1 && df -h /dev/(device path) --output\=pcent | tail -1
register: devicespace
- debug:
msg: "{{ devicespace.stdout_lines }}"
Currently, I have to hardcode each device path on the server. This specific server I am testing on has two devices How can I alter this script so that it can pull the available space on all of the devices on the server. I'v tried /dev/* but that doesn't seem to work. The end goal is to pull available space on all the devices on the server and send an email if the available space is less that 10%.
df has --output to select the fields to be printed. This can then be further processed with grep and so:
tasks:
- name: Disk usage from device
shell: df -h --output=source,pcent | grep '^/dev
register: devicespace
- debug:
msg: "{{ devicespace.stdout_lines }}"