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?
Yes, the module already checks for you. According to the documentation:
So, the module will not reformat the device if it's already formatted with the provided
fstype. To force a reformat, you can change thefstypeto something else, or setforce=true.