filesystem - Makes a filesystem

Synopsis

Requirements

The below requirements are needed on the host that executes this module.

  • Uses tools related to the fstype (mkfs) and blkid command. When resizefs is enabled, blockdev command is required too.

Parameters

Parameter Choices/Defaults Comments
dev
required
Target path to device or image file.

aliases: device
force
bool
    Choices:
  • no ←
  • yes
If yes, allows to create new filesystem on devices that already has filesystem.
fstype
required
    Choices:
  • btrfs
  • ext2
  • ext3
  • ext4
  • ext4dev
  • f2fs
  • lvm
  • ocfs2
  • reiserfs
  • xfs
  • vfat
Filesystem type to be created.
reiserfs support was added in 2.2.
lvm support was added in 2.5.
since 2.5, dev can be an image file.
vfat support was added in 2.5
ocfs2 support was added in 2.6
f2fs support was added in 2.7

aliases: type
opts
List of options to be passed to mkfs command.
resizefs
bool

(added in 2.0)
    Choices:
  • no ←
  • yes
If yes, if the block device and filesytem size differ, grow the filesystem into the space.
Supported for ext2, ext3, ext4, ext4dev, f2fs, lvm, xfs and vfat filesystems.
XFS Will only grow if mounted.
vFAT will likely fail if fatresize < 1.04.

Notes

Note

  • Potential filesystem on dev are checked using blkid, in case blkid isn’t able to detect an existing filesystem, this filesystem is overwritten even if force is no.

Examples

- name: Create a ext2 filesystem on /dev/sdb1
  filesystem:
    fstype: ext2
    dev: /dev/sdb1

- name: Create a ext4 filesystem on /dev/sdb1 and check disk blocks
  filesystem:
    fstype: ext4
    dev: /dev/sdb1
    opts: -cc

Status

This module is flagged as preview which means that it is not guaranteed to have a backwards compatible interface.

Maintenance

This module is flagged as community which means that it is maintained by the Ansible Community. See Module Maintenance & Support for more info.

For a list of other modules that are also maintained by the Ansible Community, see here.

Author

  • Alexander Bulimov (@abulimov)

Hint

If you notice any issues in this documentation you can edit this document to improve it.