Ansible mount Module: Manage Filesystem Mounts and fstab (Complete Guide)
By Luca Berton · Published 2024-01-01 · Category: installation
How to use Ansible mount module to mount filesystems, manage fstab entries, NFS mounts, tmpfs. Complete guide with playbook examples for disk management.
Ansible mount Module: Manage Filesystem Mounts and fstab (Complete Guide)
The ansible.builtin.mount module control active and configured mount points. This guide covers all common use cases with practical playbook examples.
Mount a Filesystem
NFS Mount
tmpfs Mount
Add to fstab Without Mounting
Unmount
FAQ
How do I mount a filesystem in Ansible?
Use ansible.builtin.mount with path (mount point), src (device/share), fstype, and state: mounted. This both mounts the filesystem and adds it to /etc/fstab.
What mount states are available?
mounted (mount + fstab), present (fstab only), unmounted (unmount, keep fstab), absent (unmount + remove fstab), remounted (remount with new options).
How do I mount NFS shares with Ansible?
Use mount with fstype: nfs, src: "server:/path", and appropriate opts like rw,sync,hard,intr. Ensure the nfs-common package is installed first.
Conclusion
The ansible.builtin.mount module is a versatile tool for control active and configured mount points. Use the examples above as starting points and adapt them to your infrastructure needs.
Related Articles • Ansible file Module: Manage Directories • Ansible Playbook Guide
Category: installation