community.general.filesystem module – Makes a filesystem
Note
This module is part of the community.general collection (version 10.7.5).
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
- This module creates a filesystem. 
Requirements
The below requirements are needed on the host that executes this module.
- Uses specific tools related to the - fstypefor 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-linuxor- e2fsprogspackage is required.
Parameters
| Parameter | Comments | 
|---|---|
| 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  Support for character devices on FreeBSD has been added in community.general 3.4.0. | |
| If  Choices: 
 | |
| Filesystem type to be created. This option is required with  Ufs support has been added in community.general 3.4.0. Bcachefs support has been added in community.general 8.6.0. Choices: 
 | |
| List of options to be passed to  | |
| If  Supported for  XFS only grows if mounted. Currently, the module is based on commands from  VFAT is likely to fail if  Mutually exclusive with  Choices: 
 | |
| If  If  When  Choices: 
 | |
| Set filesystem’s UUID to the given value. The UUID options specified in  See xfs_admin(8) ( For  Supported for  This is not idempotent. Specifying this option always results in a change. Mutually exclusive with  | 
Attributes
| Attribute | Support | Description | 
|---|---|---|
| Support: full | Can run in  | |
| Support: none | Will return details on what has changed (or possibly needs changing in  | 
Notes
Note
- Potential filesystems on - devare checked using- blkid. In case- blkidis unable to detect a filesystem (and in case- fstypon FreeBSD is also unable to detect a filesystem), this filesystem is overwritten even if- forceis- false.
- On FreeBSD systems, both - e2fsprogsand- util-linuxpackages provide a- blkidcommand that is compatible with this module. However, these packages conflict with each other, and only the- util-linuxpackage 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
