ansible.builtin.mount_facts module – Retrieve mount information.

Note

This module is part of ansible-core and included in all Ansible installations. In most cases, you can use the short module name mount_facts even without specifying the collections keyword. However, we recommend you use the Fully Qualified Collection Name (FQCN) ansible.builtin.mount_facts for easy linking to the module documentation and to avoid conflicting with other collections that may have the same module name.

New in ansible-core 2.18

Synopsis

  • Retrieve information about mounts from preferred sources and filter the results based on the filesystem type and device.

Parameters

Parameter

Comments

devices

list / elements=string

A list of fnmatch patterns to filter mounts by the special device or remote file system.

fstypes

list / elements=string

A list of fnmatch patterns to filter mounts by the type of the file system.

include_aggregate_mounts

boolean

Whether or not the module should return the aggregate_mounts list in ansible_facts.

When this is null, a warning will be emitted if multiple mounts for the same mount point are found.

Choices:

  • false

  • true

mount_binary

any

The mount_binary is used if sources contain the value “mount”, or if sources contains a dynamic source, and none were found (as can be expected on BSD or AIX hosts).

Set to null to stop after no dynamic file source is found instead.

Default: "mount"

on_timeout

string

The action to take when gathering mount information exceeds timeout.

Choices:

  • "error" ← (default)

  • "warn"

  • "ignore"

sources

list / elements=string

A list of sources used to determine the mounts. Missing file sources (or empty files) are skipped. Repeat sources, including symlinks, are skipped.

The mount_points return value contains the first definition found for a mount point.

Additional mounts to the same mount point are available from aggregate_mounts (if enabled).

By default, mounts are retrieved from all of the standard locations, which have the predefined aliases all/static/dynamic.

all contains dynamic and static.

dynamic contains /etc/mtab, /proc/mounts, /etc/mnttab, and the value of mount_binary if it is not None. This allows platforms like BSD or AIX, which don’t have an equivalent to /proc/mounts, to collect the current mounts by default. See the mount_binary option to disable the fall back or configure a different executable.

static contains /etc/fstab, /etc/vfstab, and /etc/filesystems. Note that /etc/filesystems is specific to AIX. The Linux file by this name has a different format/purpose and is ignored.

The value of mount_binary can be configured as a source, which will cause it to always execute. Depending on the other sources configured, this could be inefficient/redundant. For example, if /proc/mounts and mount are listed as sources, Linux hosts will retrieve the same mounts twice.

timeout

float

This is the maximum number of seconds to wait for each mount to complete. When this is null, wait indefinitely.

Configure in conjunction with on_timeout to skip unresponsive mounts.

This timeout also applies to the mount_binary command to list mounts.

If the module is configured to run during the play’s fact gathering stage, set a timeout using module_defaults to prevent a hang (see example).

Attributes

Attribute

Support

Description

check_mode

Support: full

Can run in check_mode and return changed status prediction without modifying target, if not supported the action will be skipped.

diff_mode

Support: none

Will return details on what has changed (or possibly needs changing in check_mode), when in diff mode

platform

Platform: posix

Target OS/families that can be operated against

Examples

- name: Get non-local devices
  mount_facts:
    devices: "[!/]*"

- name: Get FUSE subtype mounts
  mount_facts:
    fstypes:
      - "fuse.*"

- name: Get NFS mounts during gather_facts with timeout
  hosts: all
  gather_facts: true
  vars:
    ansible_facts_modules:
      - ansible.builtin.mount_facts
  module_default:
    ansible.builtin.mount_facts:
      timeout: 10
      fstypes:
        - nfs
        - nfs4

- name: Get mounts from a non-default location
  mount_facts:
    sources:
      - /usr/etc/fstab

- name: Get mounts from the mount binary
  mount_facts:
    sources:
      - mount
    mount_binary: /sbin/mount

Authors

  • Ansible Core Team

  • Sloane Hertel (@s-hertel)