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: