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

**URL:** <https://forum.ansible.com/t/conditionally-perform-task-only-when-a-specific-filesystem-is-or-is-not-mounted/18072>\
**Category:** Ansible Project\
**Created:** [April 24, 2015, 9:59am UTC](https://forum.ansible.com/t/conditionally-perform-task-only-when-a-specific-filesystem-is-or-is-not-mounted/18072 "2015-04-24T09:59:40Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Neech\_WORTHINGTON](https://avatars.discourse-cdn.com/v4/letter/n/e95f7d/32.png) [@Neech\_WORTHINGTON](https://forum.ansible.com/u/Neech_WORTHINGTON)\
**Post date:** [April 24, 2015, 9:59am UTC](https://forum.ansible.com/t/conditionally-perform-task-only-when-a-specific-filesystem-is-or-is-not-mounted/18072/1 "2015-04-24T09:59:40Z")

</div>

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
