From da4337b44b29d1fed3a579bfc17db1650abd42d8 Mon Sep 17 00:00:00 2001 From: shreyash bhosale Date: Tue, 9 Jun 2026 17:06:42 +0530 Subject: [PATCH] lvol: resize filesystem when LV already has the requested size When resizefs=true but the logical volume is already at the requested size, run fsadm resize to ensure the filesystem fills the device. Previously resizefs only took effect when the LV size changed --- changelogs/fragments/11620-lvol-resizefs.yml | 2 ++ plugins/modules/lvol.py | 14 ++++++++++++++ 2 files changed, 16 insertions(+) create mode 100644 changelogs/fragments/11620-lvol-resizefs.yml diff --git a/changelogs/fragments/11620-lvol-resizefs.yml b/changelogs/fragments/11620-lvol-resizefs.yml new file mode 100644 index 0000000000..b9985fce8d --- /dev/null +++ b/changelogs/fragments/11620-lvol-resizefs.yml @@ -0,0 +1,2 @@ +bugfixes: + - lvol - ``resizefs`` now resizes the filesystem even when the logical volume already has the requested size (https://github.com/ansible-collections/community.general/issues/11620). diff --git a/plugins/modules/lvol.py b/plugins/modules/lvol.py index f1b9ee8968..b3dfb047fb 100644 --- a/plugins/modules/lvol.py +++ b/plugins/modules/lvol.py @@ -90,6 +90,8 @@ options: - Resize the underlying filesystem together with the logical volume. - Supported for C(ext2), C(ext3), C(ext4), C(reiserfs) and C(XFS) filesystems. Attempts to resize other filesystem types result in failure. + - When the logical volume already has the requested size, the filesystem will still be resized to fill the logical volume + if needed. type: bool default: false notes: @@ -662,6 +664,18 @@ def main(): else: module.fail_json(msg=f"Unable to resize {lv} to {size}{size_unit}", rc=rc, err=err) + if resizefs and not changed and size: + lv_path = f"/dev/{vg}/{this_lv['name']}" + if module.check_mode: + changed = True + else: + fsadm = module.get_bin_path("fsadm", required=True) + rc, out, err = module.run_command([fsadm, "resize", lv_path]) + if rc == 0: + changed = True + else: + module.fail_json(msg=f"Failed to resize filesystem on {lv_path}", rc=rc, err=err, out=out) + if this_lv is not None: if active: with lvchange("active lv") as ctx: