here's what I've done to make it work:
---
- name: answer serverfault
hosts: all
become: yes
tasks:
- name: Apply patch if /var exist and > 300MB
debug:
msg:
#- " Data type of 'ansible_facts['mounts'] is {{ ansible_facts['mounts'] | type_debug }} "
- item mount is {{ item.mount }}
- item size_available is {{ item.size_available }}
when: item.mount == "/data" and item.size_available > 300000000
loop: "{{ ansible_facts['mounts'] | flatten(levels=1) }}"
the commented section actually shows you the datatype you're dealing with.
In this case it's a list.
To flatten the list I've used "{{ ansible_facts['mounts'] | flatten(levels=1) }}"
since the list originally looks something like this:
"ansible_mounts": [
{
"block_available": 109019876,
"block_size": 4096,
"block_total": 961159932,
"block_used": 852140056,
"device": "/dev/sde1",
"fstype": "ext4",
"inode_available": 243543185,
"inode_total": 164195328,
"inode_used": 513143,
"mount": "/data",
"options": "rw,relatime",
"size_available": 444545412096,
"size_total": 3236911081442,
"uuid": "a35a0282-6eac-132d-abdf-fbea3a835522"
},
I've tested the playbook on my /data*
mount points as I do not have server with /var
now available - but it works as expected.
some references: