# How to check file system is mounted?

**URL:** <https://forum.ansible.com/t/how-to-check-file-system-is-mounted/21516>\
**Category:** Ansible Project\
**Created:** [May 22, 2016, 9:45pm UTC](https://forum.ansible.com/t/how-to-check-file-system-is-mounted/21516 "2016-05-22T21:45:34Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Robert\_F](https://avatars.discourse-cdn.com/v4/letter/r/9d8465/32.png) [@Robert\_F](https://forum.ansible.com/u/Robert_F)\
**Post date:** [May 22, 2016, 9:45pm UTC](https://forum.ansible.com/t/how-to-check-file-system-is-mounted/21516/1 "2016-05-22T21:45:34Z")

</div>

Is there a canonical way in Ansible to check to see if a file system is mounted? The Ansible mount module doesn’t appear to provide this capability (or at least the examples don’t illustrate how it might be done). Currently I’m doing the following but it doesn’t work:

- name: check if mounted  
command: mount | grep \<file\_system\>  
register: result

- debug: var={{ result.stdout }}

I get the error:  
failed… ‘Consider using mount module rather than running mount’…  
stderr:  
Usage:  
mount [-lhV]  
…

What I’m hoping to replicate is running that command. If you run it when the file system is mounted and then do “echo $?” you’ll get “0”. However if the file system isn’t mounted, you’ll get “1”.

Thank you.

---

<div class="post-metadata">

**Author:** ![jean-yves](https://avatars.discourse-cdn.com/v4/letter/j/a587f6/32.png) [@jean-yves](https://forum.ansible.com/u/jean-yves)\
**Post date:** [May 23, 2016, 9:53am UTC](https://forum.ansible.com/t/how-to-check-file-system-is-mounted/21516/2 "2016-05-23T09:53:38Z")

</div>

Why not using the "ansible\_mounts" fact ?

Regards,

---

<div class="post-metadata">

**Author:** ![Paul\_Totterman](https://avatars.discourse-cdn.com/v4/letter/p/3ec8ea/32.png) [@Paul\_Totterman](https://forum.ansible.com/u/Paul_Totterman)\
**Post date:** [May 23, 2016, 10:42am UTC](https://forum.ansible.com/t/how-to-check-file-system-is-mounted/21516/3 "2016-05-23T10:42:29Z")

</div>

> Why not using the “ansible\_mounts” fact ?

That seems to be an array of hashes. What would be the best way to check, in your experience?

Cheers,  
Paul

---

<div class="post-metadata">

**Author:** ![Josh\_Smift1](https://avatars.discourse-cdn.com/v4/letter/j/bcef8e/32.png) [@Josh\_Smift1](https://forum.ansible.com/u/Josh_Smift1)\
**Post date:** [May 23, 2016, 10:45am UTC](https://forum.ansible.com/t/how-to-check-file-system-is-mounted/21516/4 "2016-05-23T10:45:58Z")

</div>

> Currently I'm doing the following but it doesn't work:
> 
> - name: check if mounted  
> &nbsp;&nbsp;command: mount | grep \<file\_system\>  
> &nbsp;&nbsp;register: result
> 
> - debug: var={{ result.stdout }}
> 
> I get the error:  
> failed... 'Consider using mount module rather than running mount'...  
> stderr:  
> Usage:  
> &nbsp;&nbsp;&nbsp;mount [-lhV]  
> &nbsp;&nbsp;&nbsp;...

If you can't get this with the ansible\_mounts variable for whatever  
reason, then what you're doing here should work, except that in order to  
do the pipe, you need to use the 'shell' rather than the 'command' module.

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-Josh (jbs@care.com)

(apologies for the automatic corporate disclaimer that follows)

This email is intended for the person(s) to whom it is addressed and may contain information that is PRIVILEGED or CONFIDENTIAL. Any unauthorized use, distribution, copying, or disclosure by any person other than the addressee(s) is strictly prohibited. If you have received this email in error, please notify the sender immediately by return email and delete the message and any attachments from your system.

---

<div class="post-metadata">

**Author:** ![Paul\_Totterman](https://avatars.discourse-cdn.com/v4/letter/p/3ec8ea/32.png) [@Paul\_Totterman](https://forum.ansible.com/u/Paul_Totterman)\
**Post date:** [May 23, 2016, 10:57am UTC](https://forum.ansible.com/t/how-to-check-file-system-is-mounted/21516/5 "2016-05-23T10:57:18Z")

</div>

> If you can’t get this with the ansible\_mounts variable for whatever  
> reason, then what you’re doing here should work, except that in order to  
> do the pipe, you need to use the ‘shell’ rather than the ‘command’ module.

Or:

command: mount  
register: m  
always\_run: True  
changed\_when: False  
…  
when: “‘/path’ not in m.stdout”

Cheers,  
Paul
