Reputation: 217
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?
Upvotes: 1
Views: 1424
Reputation: 5627
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
.
Upvotes: 2