Skip to content

mount

Collection Note

This module is part of the ansible.posix collection. To install the collection, use:

ansible-galaxy collection install ansible.posix
Added in version 1.0.0.

Synopsis

  • This module controls active and configured mount points in C(/etc/fstab).

Parameters

Parameter Defaults / Choices Comments
backup
bool
Create a backup file including the timestamp information so you can get the original file back if you somehow clobbered it incorrectly.
boot
bool
Default: True
Determines if the filesystem should be mounted on boot.
Only applies to Solaris and Linux systems.
For Solaris systems, C(true) will set C(yes) as the value of mount at boot in C(/etc/vfstab).
For Linux, FreeBSD, NetBSD and OpenBSD systems, C(false) will add C(noauto) to mount options in C(/etc/fstab).
To avoid mount option conflicts, if C(noauto) specified in O(opts), mount module will ignore O(boot).
This parameter is ignored when O(state=ephemeral).
dump
str
Default: 0
Dump (see fstab(5)).
Note that if set to C(null) and O(state=present), it will cease to work and duplicate entries will be made with subsequent runs.
Has no effect on Solaris systems or when used with O(state=ephemeral).
fstab
str
File to use instead of C(/etc/fstab).
You should not use this option unless you really know what you are doing.
This might be useful if you need to configure mountpoints in a chroot environment.
OpenBSD does not allow specifying alternate fstab files with mount so do not use this on OpenBSD with any state that operates on the live filesystem.
This parameter defaults to C(/etc/fstab) or C(/etc/vfstab) on Solaris.
This parameter is ignored when O(state=ephemeral).
fstype
str
Filesystem type.
Required when O(state) is V(present), V(mounted), or V(ephemeral).
opts
str
Mount options (see fstab(5), or vfstab(4) on Solaris).
opts_no_log
bool
Do not log opts.
passno
str
Default: 0
Passno (see fstab(5)).
Note that if set to C(null) and O(state=present), it will cease to work and duplicate entries will be made with subsequent runs.
Deprecated on Solaris systems. Has no effect when used with O(state=ephemeral).
path
path
required
Path to the mount point (e.g. C(/mnt/files)).
Before Ansible 2.3 this option was only usable as O(ignore:dest), O(ignore:destfile), and O(name).
src
path
Device (or NFS volume, or something else) to be mounted on I(path).
Required when O(state) set to V(present), V(mounted), or V(ephemeral).
Ignored when O(state) set to V(absent) or V(unmounted).
state
str
required
Choices: absent, absent_from_fstab, mounted, present, unmounted, remounted, ephemeral If V(mounted), the device will be actively mounted and appropriately configured in I(fstab). If the mount point is not present, the mount point will be created.
If V(unmounted), the device will be unmounted without changing I(fstab).
V(present) only specifies that the device is to be configured in I(fstab) and does not trigger or require a mount.
V(ephemeral) only specifies that the device is to be mounted, without changing I(fstab). If it is already mounted, a remount will be triggered. This will always return RV(ignore:changed=true). If the mount point O(path) has already a device mounted on, and its source is different than O(src), the module will fail to avoid unexpected unmount or mount point override. If the mount point is not present, the mount point will be created. The I(fstab) is completely ignored. This option is added in version 1.5.0.
V(absent) specifies that the mount point entry O(path) will be removed from I(fstab) and will also unmount the mounted device and remove the mount point. A mounted device will be unmounted regardless of O(src) or its real source. V(absent) does not unmount recursively, and the module will fail if multiple devices are mounted on the same mount point. Using V(absent) with a mount point that is not registered in the I(fstab) has no effect, use V(unmounted) instead.
V(remounted) specifies that the device will be remounted for when you want to force a refresh on the mount itself (added in 2.9). This will always return RV(ignore:changed=true). If O(opts) is set, the options will be applied to the remount, but will not change I(fstab). Additionally, if O(opts) is set, and the remount command fails, the module will error to prevent unexpected mount changes. Try using V(mounted) instead to work around this issue. V(remounted) expects the mount point to be present in the I(fstab). To remount a mount point not registered in I(fstab), use V(ephemeral) instead, especially with BSD nodes.
V(absent_from_fstab) specifies that the device mount's entry will be removed from I(fstab). This option does not unmount it or delete the mountpoint.

Notes

Note

  • As of Ansible 2.3, the O(name) option has been changed to O(path) as default, but O(name) still works as well.
  • Using O(state=remounted) with O(opts) set may create unexpected results based on the existing options already defined on mount, so care should be taken to ensure that conflicting options are not present before hand.

Examples

# Before 2.3, option 'name' was used instead of 'path'
- name: Mount DVD read-only
  ansible.posix.mount:
    path: /mnt/dvd
    src: /dev/sr0
    fstype: iso9660
    opts: ro,noauto
    state: present

- name: Mount up device by label
  ansible.posix.mount:
    path: /srv/disk
    src: LABEL=SOME_LABEL
    fstype: ext4
    state: present

- name: Mount up device by UUID
  ansible.posix.mount:
    path: /home
    src: UUID=b3e48f45-f933-4c8e-a700-22a159ec9077
    fstype: xfs
    opts: noatime
    state: present

- name: Unmount a mounted volume
  ansible.posix.mount:
    path: /tmp/mnt-pnt
    state: unmounted

- name: Remount a mounted volume
  ansible.posix.mount:
    path: /tmp/mnt-pnt
    state: remounted

# The following will not save changes to fstab, and only be temporary until
# a reboot, or until calling "state: unmounted" followed by "state: mounted"
# on the same "path"
- name: Remount a mounted volume and append exec to the existing options
  ansible.posix.mount:
    path: /tmp
    state: remounted
    opts: exec

- name: Mount and bind a volume
  ansible.posix.mount:
    path: /system/new_volume/boot
    src: /boot
    opts: bind
    state: mounted
    fstype: none

- name: Mount an NFS volume
  ansible.posix.mount:
    src: 192.168.1.100:/nfs/ssd/shared_data
    path: /mnt/shared_data
    opts: rw,sync,hard
    state: mounted
    fstype: nfs

- name: Mount NFS volumes with noauto according to boot option
  ansible.posix.mount:
    src: 192.168.1.100:/nfs/ssd/shared_data
    path: /mnt/shared_data
    opts: rw,sync,hard
    boot: false
    state: mounted
    fstype: nfs

- name: Mount ephemeral SMB volume
  ansible.posix.mount:
    src: //192.168.1.200/share
    path: /mnt/smb_share
    opts: "rw,vers=3,file_mode=0600,dir_mode=0700,dom={{ ad_domain }},username={{ ad_username }},password={{ ad_password }}"
    opts_no_log: true
    fstype: cifs
    state: ephemeral

Authors

  • Ansible Core Team
  • Seth Vidal (@skvidal)