Conditionally perform task only when a specific filesystem is or is not mounted

I would like to conditionally execute a task only when a specific filesystem is not mounted on the mount point “/u1/data”. So, something like the following in Pseudo-ish-code:

  • name: “Do something only when /u1/data is not mounted”
    module_action: do my module action here
    when: “not mounted /u1/data”

I notice that there is an ansible_mounts structure that is pulled back as part of (I assume) the mount module facts gathering, but I’m not sure how to write a rule for it:

“ansible_mounts”: [
{
“device”: “/dev/mapper/vg0-root”,
“fstype”: “ext4”,
“mount”: “/”,
“options”: “rw,errors=remount-ro”,
“size_available”: 15506026496,
“size_total”: 17580843008
},
{
“device”: “/dev/sda1”,
“fstype”: “ext4”,
“mount”: “/boot”,
“options”: “rw”,
“size_available”: 228306944,
“size_total”: 280992768
},
{
“device”: “/dev/mapper/vg0-u1data”,
“fstype”: “ext4”,
“mount”: “/u1/data”,
“options”: “rw,noatime”,
“size_available”: 54260461568,
“size_total”: 57174415769
}
],

I’ve had the following syntax suggested, but it doesn’t work:

when: “not ‘mount[/u1/data]’ in ansible_mounts”

I’m not very familiar with Jinja templating, so any assistance here would be greatly appreciated!

Thanks in advance