I'm trying to come up a way to iterate through ansible_mounts and, if one of the mounts is over 80% used, add that to a list that i can print out later and possibly email it. Here's what I have so far:
---
- hosts: localhost
gather_facts: no
become: yes
become_method: sudo
pre_tasks:
- setup:
filter: 'ansible_mounts'
tasks:
- name: Show the mounts and disk usage
debug:
msg: "Disk usage: {{ item.mount }} is {{ (100 * ((item.size_total - item.size_available)/item.size_total))| float | round(1, 'common') }}%"
when: "(100 * ((item.size_total - item.size_available)/item.size_total)) > 80"
with_items:
- "{{ ansible_mounts }}"
loop_control:
label: "{{ item.mount }}"
This works, but I'm not sure how to add it to a list. I'm doing this on localhost for how to get the idea solid, then I should be able to run it on other hosts. Any ideas on how to accomplish this?
Thanks,
Harry