1

I use the ansible filesystem module to format the data disks of a newly provisioned database cluster.

- name: Format data disk
  community.general.filesystem:
    fstype: ext4
    dev: /dev/sdc
    ...

But what I want is a way to automatically ckeck before formatting to make sure it doesn't run if the disk is already formatted, although I noticed that the module seems to do that checking on every run but I'm still not sure of its behavior.

Any thoughts?

double-beep
  • 5,031
  • 17
  • 33
  • 41
Rabi
  • 147
  • 2
  • 12

1 Answers1

2

Yes, the module already checks for you. According to the documentation:

If state=present, the filesystem is created if it doesn’t already exist, that is the default behaviour if state is omitted.

So, the module will not reformat the device if it's already formatted with the provided fstype. To force a reformat, you can change the fstype to something else, or set force=true.

Garrett Hyde
  • 5,409
  • 8
  • 49
  • 55