ansible_mounts is an array of dictionaries, like so -
"ansible_mounts": [ { "device": "/dev/mapper/vg_centos67template-lv_root", "fstype": "ext4", "mount": "/", "options": "rw", "size_available": 8806977536, "size_total": 37458894848, "uuid": "N/A" }, { "device": "/dev/sda1", "fstype": "ext4", "mount": "/boot", "options": "rw", "size_available": 369055744, "size_total": 499355648, "uuid": "N/A" }, ],
I need to confirm a set of specific mount points exist, with minimum sizes. I have control of the data structure for this, but for now have structured it similarly -
requiredMounts:
- { mount: /tmp, size_min: 2147483648, }
- { mount: /dev/shm, size_min: 204010946560, }
I was hoping to use a selectattr() filter like a grep, but it isn't available.
fatal: [tstServer]: FAILED! => {"failed": true, "msg": "template error while templating string: no filter named 'selectattr'. String: {{ ansible_mounts | selectattr( 'mount', 'equalto', item.mount ) }}"}
Using jinja 2.6. No idea why selectattr() isn't there.
(That's jenkins output, if anyone cares.)
Happy to use when, fail, assert, with_items, with_nested, combine(), and/or anything else; just haven't found quite the right combination to make it neat. I'd rather it not take a dozen steps - one would be ideal.
Suggestions?
Addendum:
I can confirm mount points pretty easily in one step with a fail: ... when: not item.mount|is_mount
...which is interesting, because while /dev/shm
shows as a mount point this way (and from command like df
& mount
) it isn't included in ansible_mounts
.
That means I can't just use ansible_mounts
to check file sizes in a separate with_nested
for /dev/shm
. This makes me a sad panda.
Further addendum:
Turns out I have to check one mount point (/tmp) that is generally available through the usual filesystem - best option ansible_mounts! - one (/dev/shm) that is tempfs - easiest seems to be df, which can also handle /tmp - and a bunch that oracle manages, so they are only available through fdisk.
In the end it turns out that I have to check well over a dozen drives per system, but that /tmp is the only one available to ansible_mounts. That being said, my question becomes moot the way I asked it...
Thanks for the input.