Skip to content

mount_facts

Collection Note

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

ansible-galaxy collection install ansible.builtin
Added in version 2.18.

Synopsis

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

Parameters

Parameter Defaults / Choices Comments
devices
list / elements=str
A list of fnmatch patterns to filter mounts by the special device or remote file system.
fstypes
list / elements=str
A list of fnmatch patterns to filter mounts by the type of the file system.
include_aggregate_mounts
bool
Whether or not the module should return the C(aggregate_mounts) list in C(ansible_facts).
When this is V(null), a warning will be emitted if multiple mounts for the same mount point are found.
mount_binary
raw
Default: mount
The O(mount_binary) is used if O(sources) contain the value "mount", or if O(sources) contains a dynamic source, and none were found (as can be expected on BSD or AIX hosts).
Set to V(null) to stop after no dynamic file source is found instead.
on_timeout
str
Default: error
Choices: error, warn, ignore
The action to take when gathering mount information exceeds O(timeout).
sources
list / elements=str
A list of sources used to determine the mounts. Missing file sources (or empty files) are skipped. Repeat sources, including symlinks, are skipped.
The C(mount_points) return value contains the first definition found for a mount point.
Additional mounts to the same mount point are available from C(aggregate_mounts) (if enabled).
By default, mounts are retrieved from all of the standard locations, which have the predefined aliases V(all)/V(static)/V(dynamic).
V(all) contains V(dynamic) and V(static).
V(dynamic) contains V(/etc/mtab), V(/proc/mounts), V(/etc/mnttab), and the value of O(mount_binary) if it is not None. This allows platforms like BSD or AIX, which don't have an equivalent to V(/proc/mounts), to collect the current mounts by default. See the O(mount_binary) option to disable the fall back or configure a different executable.
V(static) contains V(/etc/fstab), V(/etc/vfstab), and V(/etc/filesystems). Note that V(/etc/filesystems) is specific to AIX. The Linux file by this name has a different format/purpose and is ignored.
The value of O(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 V(/proc/mounts) and V(mount) are listed as O(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 V(null), wait indefinitely.
Configure in conjunction with O(on_timeout) to skip unresponsive mounts.
This timeout also applies to the O(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).

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

Return Values

Key Data Type Description Returned
ansible_facts dict An ansible_facts dictionary containing a dictionary of C(mount_points) and list of C(aggregate_mounts) when enabled. Each key in C(mount_points) is a mount point, and the value contains mount information (similar to C(ansible_facts["mounts"])). Each value also contains the key C(ansible_context), with details about the source and line(s) corresponding to the parsed mount point. When C(aggregate_mounts) are included, the containing dictionaries are the same format as the C(mount_point) values. on success

Authors

  • Ansible Core Team
  • Sloane Hertel (@s-Hertel)