# Ansible playbook how to view and expand multiple existing lvms in multiple lvgs in rhel 8

**URL:** <https://forum.ansible.com/t/ansible-playbook-how-to-view-and-expand-multiple-existing-lvms-in-multiple-lvgs-in-rhel-8/10287>\
**Category:** Get Help\
**Tags:** rhel\
**Created:** [October 14, 2024, 9:11pm UTC](https://forum.ansible.com/t/ansible-playbook-how-to-view-and-expand-multiple-existing-lvms-in-multiple-lvgs-in-rhel-8/10287 "2024-10-14T21:11:34Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jewebe22](https://avatars.discourse-cdn.com/v4/letter/j/3bc359/32.png) [@jewebe22](https://forum.ansible.com/u/jewebe22)\
**Post date:** [October 14, 2024, 9:11pm UTC](https://forum.ansible.com/t/ansible-playbook-how-to-view-and-expand-multiple-existing-lvms-in-multiple-lvgs-in-rhel-8/10287/1 "2024-10-14T21:11:34Z")

</div>

Hi, i’m looking to add a step that checks and prints the current sizes of existing lv’s in a volume group before expanding them. Currently, I have a play that will extend the size of multiple lvm’s assuming the vg has enough space. I’m not sure whats the best way to determine the current sizes of the existing lvms. My first thought is to maybe create a role that uses the shell command that then runs vgs and lvs to capture and print current size and free space of lv’s and vg but not sure if thats the best way. Here is my current code:

* * *

- name: Extend the logical volume to take all remaining space of the PVs and resize the underlying filesystem  
vars:  
lvextendAudit: False  
lvextendAuditSize: 4096  
#lvextendAuditSize: 4096  
##------------------------  
lvextendOpt: True  
lvextendOptSize: 40g  
#lvextendOptSize: 5120  
block:
  - name: Extend the Audit Logical Volume  
lvol:  
vg: rhel  
lv: audit  
size: ‘{{ lvextendAuditSize }}’  
resizefs: true  
shrink: no  
when: lvextendAudit
  - name: Extend the OPT Logical Volume  
lvol:  
vg: rhel  
lv: opt  
size: ‘{{ lvextendOptSize }}’  
resizefs: true  
shrink: no  
when: lvextendOpt  
…

---

<div class="post-metadata">

**Author:** ![utoddl](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/utoddl/32/249_2.png) [@utoddl](https://forum.ansible.com/u/utoddl)\
**Post date:** [October 15, 2024, 9:17pm UTC](https://forum.ansible.com/t/ansible-playbook-how-to-view-and-expand-multiple-existing-lvms-in-multiple-lvgs-in-rhel-8/10287/2 "2024-10-15T21:17:36Z")

</div>

If you look at `community/general/plugins/modules/lvol.py` (and `lvg.py` and `lvg_rename.py` in that same directory) you can see that those modules are python wrappers around the respective commands. You could go so far as to model a `vgs` and `lvs` module plugin after them, or you could (probably more easily if not as robustly) do the same thing with `ansible.builtin.shell`.

Since you’re writing this for your own use, you can probably be less strict in specifying inputs. Even if you do decide to use `ansible.builtin.shell`, it’s worth looking over those other plugin source files to see what sort of issues they anticipate and deal with.

* * *

By the way, if you’re posting YAML, put it between “tripple-tick” lines so it displays properly, like this:

````
```yaml
---
- name: My pretty YAML
  hosts: localhost
  […]
```

````

It’ll make your posts easier for everyone to read, and greatly increase your chances of getting feedback.

Cheers!
