
Grow an LVM Logical Volume with Ansible on RHEL
Example for supported RHEL 8/9 systems with a simple, unencrypted LVM layout. Review collection and managed-host requirements before use.
Ansible can make a storage expansion repeatable, but it cannot decide whether the selected disk is safe to change. This example grows a final partition, refreshes the existing physical volume and sets an existing logical volume to an absolute target size. It replaces prompt-driven fdisk automation, which is fragile across disk layouts and versions.

Confirm the layout and collection versions
Use the manual LVM checks first. Verify the disk, partition number, existing PV/VG/LV, filesystem, adjacent free space and backup. The example assumes /dev/sda2 already belongs to rhel and that root already exists. It must not be used to create a new layout or to change encrypted, multipath, RAID or thin-pool storage.
Install a compatible community.general collection on the controller or AWX execution environment. The remove_extra_pvs option below requires community.general 10.4.0 or later. Confirm that its Ansible/Python requirements fit your environment, and pin the chosen version in your automation project.
Use an absolute target size
---
- name: Grow an existing RHEL logical volume
hosts: storage_targets
become: true
serial: 1
vars:
disk_device: /dev/sda
partition_number: "2"
pv_device: /dev/sda2
vg_name: rhel
lv_name: root
target_lv_size: 30g # Example absolute size; review for each host.
pre_tasks:
- name: Verify the selected PV already belongs to the expected VG
ansible.builtin.command:
argv: [pvs, --noheadings, --options, vg_name, "{{ pv_device }}"]
register: pv_membership
changed_when: false
check_mode: false
failed_when: >-
pv_membership.rc != 0 or
(pv_membership.stdout | trim) != vg_name
- name: Verify the logical volume already exists
ansible.builtin.command:
argv: [lvs, --noheadings, "{{ vg_name }}/{{ lv_name }}"]
changed_when: false
check_mode: false
tasks:
- name: Install partition growth utility
ansible.builtin.package:
name: cloud-utils-growpart
state: present
- name: Grow the existing final partition
ansible.builtin.command:
argv: [growpart, "{{ disk_device }}", "{{ partition_number }}"]
register: partition_growth
changed_when: partition_growth.rc == 0
failed_when: >-
partition_growth.rc not in [0, 1] or
(partition_growth.rc == 1 and
'NOCHANGE' not in (partition_growth.stdout | default('')))
when: not ansible_check_mode
- name: Refresh the existing PV without removing other VG members
community.general.lvg:
vg: "{{ vg_name }}"
pvs: ["{{ pv_device }}"]
pvresize: true
remove_extra_pvs: false
- name: Grow the existing LV and filesystem to the target size
community.general.lvol:
vg: "{{ vg_name }}"
lv: "{{ lv_name }}"
size: "{{ target_lv_size }}"
shrink: false
resizefs: true
Use a target larger than the existing LV and within the final available VG capacity. shrink: false prevents reducing an oversized LV. An absolute size avoids adding another increment on every run; relative sizes such as +100%FREE are not inherently idempotent. Preserving other VG members prevents an incomplete PV list from being interpreted as a removal request.
Run against one reviewed host and verify
ansible-playbook grow-lvm.yml --syntax-check
ansible-playbook grow-lvm.yml --limit server01.example.com
The target must already be in the authorized inventory. Check mode skips partition growth here, so it cannot prove that later tasks will succeed using the enlarged geometry. After a real run, check pvs, vgs, lvs and df -hT, then test the application. Stop on partition-table or filesystem errors instead of suppressing them. Keep the pre-change backup and metadata until acceptance is complete.