community.general.filesystem (8.5.0) — module

Makes a filesystem

Authors: Alexander Bulimov (@abulimov), quidame (@quidame)

Install collection

Install with ansible-galaxy collection install community.general:==8.5.0


Add to requirements.yml

  collections:
    - name: community.general
      version: 8.5.0

Description

This module creates a filesystem.


Requirements

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Create a ext2 filesystem on /dev/sdb1
  community.general.filesystem:
    fstype: ext2
    dev: /dev/sdb1
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Create a ext4 filesystem on /dev/sdb1 and check disk blocks
  community.general.filesystem:
    fstype: ext4
    dev: /dev/sdb1
    opts: -cc
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Blank filesystem signature on /dev/sdb1
  community.general.filesystem:
    dev: /dev/sdb1
    state: absent
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Create a filesystem on top of a regular file
  community.general.filesystem:
    dev: /path/to/disk.img
    fstype: vfat
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Reset an xfs filesystem UUID on /dev/sdb1
  community.general.filesystem:
    fstype: xfs
    dev: /dev/sdb1
    uuid: generate
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Reset an ext4 filesystem UUID on /dev/sdb1
  community.general.filesystem:
    fstype: ext4
    dev: /dev/sdb1
    uuid: random
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Reset an LVM filesystem (PV) UUID on /dev/sdc
  community.general.filesystem:
    fstype: lvm
    dev: /dev/sdc
    uuid: random

Inputs

    
dev:
    aliases:
    - device
    description:
    - Target path to block device (Linux) or character device (FreeBSD) or regular file
      (both).
    - When setting Linux-specific filesystem types on FreeBSD, this module only works
      when applying to regular files, aka disk images.
    - Currently V(lvm) (Linux-only) and V(ufs) (FreeBSD-only) do not support a regular
      file as their target O(dev).
    - Support for character devices on FreeBSD has been added in community.general 3.4.0.
    required: true
    type: path

opts:
    description:
    - List of options to be passed to C(mkfs) command.
    type: str

uuid:
    description:
    - Set filesystem's UUID to the given value.
    - The UUID options specified in O(opts) take precedence over this value.
    - See xfs_admin(8) (C(xfs)), tune2fs(8) (C(ext2), C(ext3), C(ext4), C(ext4dev)) for
      possible values.
    - For O(fstype=lvm) the value is ignored, it resets the PV UUID if set.
    - Supported for O(fstype) being one of C(ext2), C(ext3), C(ext4), C(ext4dev), C(lvm),
      or C(xfs).
    - This is B(not idempotent). Specifying this option will always result in a change.
    - Mutually exclusive with O(resizefs).
    type: str
    version_added: 7.1.0
    version_added_collection: community.general

force:
    default: false
    description:
    - If V(true), allows to create new filesystem on devices that already has filesystem.
    type: bool

state:
    choices:
    - present
    - absent
    default: present
    description:
    - If O(state=present), the filesystem is created if it doesn't already exist, that
      is the default behaviour if O(state) is omitted.
    - If O(state=absent), filesystem signatures on O(dev) are wiped if it contains a filesystem
      (as known by C(blkid)).
    - When O(state=absent), all other options but O(dev) are ignored, and the module does
      not fail if the device O(dev) doesn't actually exist.
    type: str
    version_added: 1.3.0
    version_added_collection: community.general

fstype:
    aliases:
    - type
    choices:
    - btrfs
    - ext2
    - ext3
    - ext4
    - ext4dev
    - f2fs
    - lvm
    - ocfs2
    - reiserfs
    - xfs
    - vfat
    - swap
    - ufs
    description:
    - Filesystem type to be created. This option is required with O(state=present) (or
      if O(state) is omitted).
    - ufs support has been added in community.general 3.4.0.
    type: str

resizefs:
    default: false
    description:
    - If V(true), if the block device and filesystem size differ, grow the filesystem
      into the space.
    - Supported for C(btrfs), C(ext2), C(ext3), C(ext4), C(ext4dev), C(f2fs), C(lvm),
      C(xfs), C(ufs) and C(vfat) filesystems. Attempts to resize other filesystem types
      will fail.
    - XFS Will only grow if mounted. Currently, the module is based on commands from C(util-linux)
      package to perform operations, so resizing of XFS is not supported on FreeBSD systems.
    - vFAT will likely fail if C(fatresize < 1.04).
    - Mutually exclusive with O(uuid).
    type: bool

See also