zombi_man zombi_man - 4 months ago 79x
Linux Question

Ansible: is it possible to resize ext4 filesystem?

How I can resize ext4 filesystem via Ansible? I know about the filesystem module, but I didn't see a "resize" parameter, or something else about it ...


If you look at the source of the filesystem module as it currently stands, you can see that there doesn't seem to be anything you could use to resize a filesystem.

Thankfully, you have options: the command module and the shell module.

The command module is preferred over the shell module because it's not affected by the user environment, so I'll show you how to do it using the approach:

- name: "resize my ext4 filesystem, please"
  command: resize2fs /dev/sda1 
  sudo: True

where sda1 is your filesystem. If you need to enlarge your filesystem first, use the same approach, but make a call to fdisk (with the correct command line switches) instead.

Check man resize2fs for specific options for that command and the ansible documentation for more information, including parameterizing your command.