• Blog
  • Ansible community forum
  • Documentation
Ansible Logo
Ansible Community Documentation
Ansible

Ansible getting started

  • Getting started with Ansible
  • Getting started with Execution Environments

Installation, Upgrade & Configuration

  • Installation Guide
  • Ansible Porting Guides

Using Ansible

  • Building Ansible inventories
  • Using Ansible command line tools
  • Using Ansible playbooks
  • Protecting sensitive data with Ansible vault
  • Using Ansible modules and plugins
  • Using Ansible collections
  • Using Ansible on Windows, BSD, and z/OS UNIX
  • Ansible tips and tricks

Contributing to Ansible

  • Ansible Community Guide
  • Ansible Collections Contributor Guide
  • ansible-core Contributors Guide
  • Advanced Contributor Guide
  • Ansible documentation style guide

Extending Ansible

  • Developer Guide

Common Ansible Scenarios

  • Legacy Public Cloud Guides

Network Automation

  • Network Getting Started
  • Network Advanced Topics
  • Network Developer Guide

Ansible Galaxy

  • Galaxy User Guide
  • Galaxy Developer Guide

Reference & Appendices

  • Collection Index
    • Collections in the Amazon Namespace
    • Collections in the Ansible Namespace
    • Collections in the Arista Namespace
    • Collections in the Awx Namespace
    • Collections in the Azure Namespace
    • Collections in the Check_point Namespace
    • Collections in the Chocolatey Namespace
    • Collections in the Cisco Namespace
    • Collections in the Cloud Namespace
    • Collections in the Cloudscale_ch Namespace
    • Collections in the Community Namespace
      • Community.Aws
      • Community.Ciscosmb
      • Community.Crypto
      • Community.Digitalocean
      • Community.Dns
      • Community.Docker
      • Community.General
        • Description
        • Communication
        • Changelog
        • Guides
        • Cloud Guides
        • Developer Guides
        • Plugin Index
      • Community.Grafana
      • Community.Hashi_Vault
      • Community.Hrobot
      • Community.Library_Inventory_Filtering_V1
      • Community.Libvirt
      • Community.Mongodb
      • Community.Mysql
      • Community.Network
      • Community.Okd
      • Community.Postgresql
      • Community.Proxysql
      • Community.Rabbitmq
      • Community.Routeros
      • Community.Sap_Libs
      • Community.Sops
      • Community.Vmware
      • Community.Windows
      • Community.Zabbix
    • Collections in the Containers Namespace
    • Collections in the Cyberark Namespace
    • Collections in the Dellemc Namespace
    • Collections in the F5networks Namespace
    • Collections in the Fortinet Namespace
    • Collections in the Frr Namespace
    • Collections in the Gluster Namespace
    • Collections in the Google Namespace
    • Collections in the Grafana Namespace
    • Collections in the Hetzner Namespace
    • Collections in the Hitachivantara Namespace
    • Collections in the Hpe Namespace
    • Collections in the Ibm Namespace
    • Collections in the Ieisystem Namespace
    • Collections in the Infinidat Namespace
    • Collections in the Infoblox Namespace
    • Collections in the Inspur Namespace
    • Collections in the Junipernetworks Namespace
    • Collections in the Kaytus Namespace
    • Collections in the Kubernetes Namespace
    • Collections in the Kubevirt Namespace
    • Collections in the Lowlydba Namespace
    • Collections in the Mellanox Namespace
    • Collections in the Microsoft Namespace
    • Collections in the Netapp Namespace
    • Collections in the Netapp_eseries Namespace
    • Collections in the Netbox Namespace
    • Collections in the Ngine_io Namespace
    • Collections in the Openstack Namespace
    • Collections in the Openvswitch Namespace
    • Collections in the Ovirt Namespace
    • Collections in the Purestorage Namespace
    • Collections in the Sensu Namespace
    • Collections in the Servicenow Namespace
    • Collections in the Splunk Namespace
    • Collections in the T_systems_mms Namespace
    • Collections in the Telekom_mms Namespace
    • Collections in the Theforeman Namespace
    • Collections in the Vmware Namespace
    • Collections in the Vultr Namespace
    • Collections in the Vyos Namespace
    • Collections in the Wti Namespace
  • Indexes of all modules and plugins
  • Playbook Keywords
  • Return Values
  • Ansible Configuration Settings
  • Controlling how Ansible behaves: precedence rules
  • YAML Syntax
  • Python 3 Support
  • Interpreter Discovery
  • Releases and maintenance
  • Testing Strategies
  • Sanity Tests
  • Frequently Asked Questions
  • Glossary
  • Ansible Reference: Module Utilities
  • Special Variables
  • Red Hat Ansible Automation Platform
  • Ansible Automation Hub
  • Logging Ansible output

Roadmaps

  • Ansible Roadmap
  • ansible-core Roadmaps




Ansible
  • Collection Index
  • Collections in the Community Namespace
  • Community.General
  • community.general.filesystem module – Makes a filesystem
  • Edit on GitHub

'; // Create a banner if we're not on the official docs site if (location.host == "docs.testing.ansible.com") { document.write('
' + '

This is the testing site for Ansible Documentation. Unless you are reviewing pre-production changes, please visit the official documentation website.

' + '
'); } // Create a banner current_url_path = window.location.pathname; var important = false; var msg = '

'; if (startsWith(current_url_path, "/ansible-core/")) { msg += 'You are reading documentation for Ansible Core, which contains no plugins except for those in ansible.builtin. For documentation of the Ansible package, go to the latest documentation.'; } else if (startsWithOneOf(current_url_path, ["/ansible/latest/", "/ansible/11/"])) { /* temp extra banner to advertise something */ banner += extra_banner; msg += 'This is the latest (stable) Ansible community documentation. For Red Hat Ansible Automation Platform subscriptions, see Life Cycle for version details.'; } else if (startsWith(current_url_path, "/ansible/2.9/")) { msg += 'You are reading the latest Red Hat released version of the Ansible documentation. Community users can use this version, or select latest from the version selector to the left for the most recent community version.'; } else if (startsWith(current_url_path, "/ansible/devel/")) { /* temp extra banner to advertise something */ banner += extra_banner; msg += 'You are reading the devel version of the Ansible documentation - this version is not guaranteed stable. Use the version selection to the left if you want the latest (stable) released version.'; } else { msg += 'You are reading an older version of the Ansible documentation. Use the version selection to the left if you want the latest (stable) released version.'; /* temp extra banner to advertise something - this is for testing*/ banner += extra_banner; } msg += '

'; banner += '
'; banner += important ? '
' : ''; banner += msg; banner += important ? '
' : ''; banner += '
'; document.write(banner);

community.general.filesystem module – Makes a filesystem

Note

This module is part of the community.general collection (version 10.7.0).

You might already have this collection installed if you are using the ansible package. It is not included in ansible-core. To check whether it is installed, run ansible-galaxy collection list.

To install it, use: ansible-galaxy collection install community.general. You need further requirements to be able to use this module, see Requirements for details.

To use it in a playbook, specify: community.general.filesystem.

  • Synopsis

  • Requirements

  • Parameters

  • Attributes

  • Notes

  • See Also

  • Examples

Synopsis

  • This module creates a filesystem.

Requirements

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

  • Uses specific tools related to the fstype for creating or resizing a filesystem (from packages e2fsprogs, xfsprogs, dosfstools, and so on).

  • Uses generic tools mostly related to the Operating System (Linux or FreeBSD) or available on both, as blkid.

  • On FreeBSD, either util-linux or e2fsprogs package is required.

Parameters

Parameter

Comments

dev

aliases: device

path / required

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 lvm (Linux-only) and ufs (FreeBSD-only) do not support a regular file as their target dev.

Support for character devices on FreeBSD has been added in community.general 3.4.0.

force

boolean

If true, allows to create new filesystem on devices that already has filesystem.

Choices:

  • false ← (default)

  • true

fstype

aliases: type

string

Filesystem type to be created. This option is required with state=present (or if state is omitted).

Ufs support has been added in community.general 3.4.0.

Bcachefs support has been added in community.general 8.6.0.

Choices:

  • "bcachefs"

  • "btrfs"

  • "ext2"

  • "ext3"

  • "ext4"

  • "ext4dev"

  • "f2fs"

  • "lvm"

  • "ocfs2"

  • "reiserfs"

  • "xfs"

  • "vfat"

  • "swap"

  • "ufs"

opts

string

List of options to be passed to mkfs command.

resizefs

boolean

If true, if the block device and filesystem size differ, grow the filesystem into the space.

Supported for bcachefs, btrfs, ext2, ext3, ext4, ext4dev, f2fs, lvm, xfs, ufs and vfat filesystems. Attempts to resize other filesystem types will fail.

XFS Will only grow if mounted. Currently, the module is based on commands from util-linux package to perform operations, so resizing of XFS is not supported on FreeBSD systems.

VFAT will likely fail if fatresize < 1.04.

Mutually exclusive with uuid.

Choices:

  • false ← (default)

  • true

state

string

added in community.general 1.3.0

If state=present, the filesystem is created if it does not already exist, that is the default behaviour if state is omitted.

If state=absent, filesystem signatures on dev are wiped if it contains a filesystem (as known by blkid).

When state=absent, all other options but dev are ignored, and the module does not fail if the device dev does not actually exist.

Choices:

  • "present" ← (default)

  • "absent"

uuid

string

added in community.general 7.1.0

Set filesystem’s UUID to the given value.

The UUID options specified in opts take precedence over this value.

See xfs_admin(8) (xfs), tune2fs(8) (ext2, ext3, ext4, ext4dev) for possible values.

For fstype=lvm the value is ignored, it resets the PV UUID if set.

Supported for fstype being one of bcachefs, ext2, ext3, ext4, ext4dev, lvm, or xfs.

This is not idempotent. Specifying this option will always result in a change.

Mutually exclusive with resizefs.

Attributes

Attribute

Support

Description

check_mode

Support: full

Can run in check_mode and return changed status prediction without modifying target.

diff_mode

Support: none

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

Notes

Note

  • Potential filesystems on dev are checked using blkid. In case blkid is unable to detect a filesystem (and in case fstyp on FreeBSD is also unable to detect a filesystem), this filesystem is overwritten even if force is false.

  • On FreeBSD systems, both e2fsprogs and util-linux packages provide a blkid command that is compatible with this module. However, these packages conflict with each other, and only the util-linux package provides the command required to not fail when state=absent.

See Also

See also

community.general.filesize

Create a file with a given size, or resize it if it exists.

ansible.posix.mount

Control active and configured mount points.

xfs_admin(8) manpage for Linux

Manual page of the GNU/Linux’s xfs_admin implementation.

tune2fs(8) manpage for Linux

Manual page of the GNU/Linux’s tune2fs implementation.

Examples

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

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

- name: Blank filesystem signature on /dev/sdb1
  community.general.filesystem:
    dev: /dev/sdb1
    state: absent

- name: Create a filesystem on top of a regular file
  community.general.filesystem:
    dev: /path/to/disk.img
    fstype: vfat

- name: Reset an xfs filesystem UUID on /dev/sdb1
  community.general.filesystem:
    fstype: xfs
    dev: /dev/sdb1
    uuid: generate

- name: Reset an ext4 filesystem UUID on /dev/sdb1
  community.general.filesystem:
    fstype: ext4
    dev: /dev/sdb1
    uuid: random

- name: Reset an LVM filesystem (PV) UUID on /dev/sdc
  community.general.filesystem:
    fstype: lvm
    dev: /dev/sdc
    uuid: random

Authors

  • Alexander Bulimov (@abulimov)

  • quidame (@quidame)

Collection links

  • Issue Tracker
  • Repository (Sources)
  • Ask for help
  • Submit a bug report
  • Request a feature
  • Communication
Previous Next

© Copyright Ansible project contributors. Last updated on Jun 12, 2025.