Iterating ansible_mounts and adding items to a list

36 views
Skip to first unread message

harry devine

unread,
Apr 13, 2020, 2:15:52 PM4/13/20
to Ansible Project
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
Reply all
Reply to author
Forward
0 new messages