ansible.posix.mount (1.5.4) — module

Control active and configured mount points

| "added in version" 1.0.0 of ansible.posix"

Authors: Ansible Core Team, Seth Vidal (@skvidal)

Install collection

Install with ansible-galaxy collection install ansible.posix:==1.5.4


Add to requirements.yml

  collections:
    - name: ansible.posix
      version: 1.5.4

Description

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

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# 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
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Mount up device by label
  ansible.posix.mount:
    path: /srv/disk
    src: LABEL=SOME_LABEL
    fstype: ext4
    state: present
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Mount up device by UUID
  ansible.posix.mount:
    path: /home
    src: UUID=b3e48f45-f933-4c8e-a700-22a159ec9077
    fstype: xfs
    opts: noatime
    state: present
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Unmount a mounted volume
  ansible.posix.mount:
    path: /tmp/mnt-pnt
    state: unmounted
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Remount a mounted volume
  ansible.posix.mount:
    path: /tmp/mnt-pnt
    state: remounted
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# 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
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Mount and bind a volume
  ansible.posix.mount:
    path: /system/new_volume/boot
    src: /boot
    opts: bind
    state: mounted
    fstype: none
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- 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
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- 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
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- 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 }}"
    fstype: cifs
    state: ephemeral

Inputs

    
src:
    description:
    - Device (or NFS volume, or something else) to be mounted on I(path).
    - Required when I(state) set to C(present), C(mounted) or C(ephemeral).
    type: path

boot:
    default: true
    description:
    - 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 I(/etc/vfstab).
    - For Linux, FreeBSD, NetBSD and OpenBSD systems, C(false) will add C(noauto) to mount
      options in I(/etc/fstab).
    - To avoid mount option conflicts, if C(noauto) specified in C(opts), mount module
      will ignore C(boot).
    - This parameter is ignored when I(state) is set to C(ephemeral).
    type: bool

dump:
    default: '0'
    description:
    - Dump (see fstab(5)).
    - Note that if set to C(null) and I(state) set to C(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 C(ephemeral).
    type: str

opts:
    description:
    - Mount options (see fstab(5), or vfstab(4) on Solaris).
    type: str

path:
    aliases:
    - name
    description:
    - Path to the mount point (e.g. C(/mnt/files)).
    - Before Ansible 2.3 this option was only usable as I(dest), I(destfile) and I(name).
    required: true
    type: path

fstab:
    description:
    - 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 /etc/fstab or /etc/vfstab on Solaris.
    - This parameter is ignored when I(state) is set to C(ephemeral).
    type: str

state:
    choices:
    - absent
    - absent_from_fstab
    - mounted
    - present
    - unmounted
    - remounted
    - ephemeral
    description:
    - If C(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 C(unmounted), the device will be unmounted without changing I(fstab).
    - C(present) only specifies that the device is to be configured in I(fstab) and does
      not trigger or require a mount.
    - C(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 changed=True.
      If the mount point I(path) has already a device mounted on, and its source is different
      than I(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.
    - C(absent) specifies that the device mount's entry will be removed from I(fstab)
      and will also unmount the device and remove the mount point.
    - C(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 changed=true.
      If I(opts) is set, the options will be applied to the remount, but will not change
      I(fstab).  Additionally, if I(opts) is set, and the remount command fails, the module
      will error to prevent unexpected mount changes.  Try using C(mounted) instead to
      work around this issue.  C(remounted) expects the mount point to be present in the
      I(fstab). To remount a mount point not registered in I(fstab), use C(ephemeral)
      instead, especially with BSD nodes.
    - C(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.
    required: true
    type: str

backup:
    default: false
    description:
    - Create a backup file including the timestamp information so you can get the original
      file back if you somehow clobbered it incorrectly.
    type: bool

fstype:
    description:
    - Filesystem type.
    - Required when I(state) is C(present), C(mounted) or C(ephemeral).
    type: str

passno:
    default: '0'
    description:
    - Passno (see fstab(5)).
    - Note that if set to C(null) and I(state) set to C(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 C(ephemeral).
    type: str