# print highest number of volume group

**URL:** <https://forum.ansible.com/t/print-highest-number-of-volume-group/33188>\
**Category:** Ansible Project\
**Created:** [June 15, 2020, 8:25pm UTC](https://forum.ansible.com/t/print-highest-number-of-volume-group/33188 "2020-06-15T20:25:38Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sharanpeetani](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sharanpeetani/32/8509_2.png) [@sharanpeetani](https://forum.ansible.com/u/sharanpeetani)\
**Post date:** [June 15, 2020, 8:25pm UTC](https://forum.ansible.com/t/print-highest-number-of-volume-group/33188/1 "2020-06-15T20:25:38Z")

</div>

Hello,

I

Is there a way to print only volume group name on server with the highest number? for eg if the server has vg00, vg01, vg02 I want to have print only highest number vg which is vg02. I am trying to use with ansible\_lvm.vgs but couldnt able to. With shell command I am able to get the info but wondering if its possible with ansible\_lvm facts.

- debug:  
var: item  
with\_items:

- “{{ ansible\_lvm.vgs }}”

- shell: vgs --noheadings | grep -E “vg[0-9]” | sort | tail -n1 | awk ‘{print $1}’  
register: highest

- debug:  
var: highest.stdout

Output:

PLAY [all] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

TASK [Gathering Facts] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [[rhel7.lab.com](http://rhel7.lab.com)]

TASK [debug] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [[rhel7.lab.com](http://rhel7.lab.com)] =\> (item={‘vg09’: {‘free\_g’: ‘5.00’, ‘size\_g’: ‘5.00’, ‘num\_lvs’: ‘0’, ‘num\_pvs’: ‘1’}, ‘vg00’: {‘free\_g’: ‘10.00’, ‘size\_g’: ‘10.00’, ‘num\_lvs’: ‘0’, ‘num\_pvs’: ‘1’}}) =\>  
ansible\_loop\_var: item  
item:  
vg00:  
free\_g: ‘10.00’  
num\_lvs: ‘0’  
num\_pvs: ‘1’  
size\_g: ‘10.00’  
vg09:  
free\_g: ‘5.00’  
num\_lvs: ‘0’  
num\_pvs: ‘1’  
size\_g: ‘5.00’

TASK [shell] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
changed: [[rhel7.lab.com](http://rhel7.lab.com)]

TASK [debug] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [[rhel7.lab.com](http://rhel7.lab.com)] =\>  
highest.stdout: vg09

PLAY RECAP \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
[rhel7.lab.com](http://rhel7.lab.com) : ok=5 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0  
Thank you.

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [June 15, 2020, 9:18pm UTC](https://forum.ansible.com/t/print-highest-number-of-volume-group/33188/2 "2020-06-15T21:18:00Z")

</div>

Try:

"{{ ansible\_lvm.lvs | select('match', '^vg[0-9]+') | list | sort | last }}"

---

<div class="post-metadata">

**Author:** ![sharanpeetani](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sharanpeetani/32/8509_2.png) [@sharanpeetani](https://forum.ansible.com/u/sharanpeetani)\
**Post date:** [June 15, 2020, 10:57pm UTC](https://forum.ansible.com/t/print-highest-number-of-volume-group/33188/3 "2020-06-15T22:57:08Z")

</div>

Thank you Dick Visser. It’s working for me.

---

<div class="post-metadata">

**Author:** ![sharanpeetani](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sharanpeetani/32/8509_2.png) [@sharanpeetani](https://forum.ansible.com/u/sharanpeetani)\
**Post date:** [June 16, 2020, 11:17am UTC](https://forum.ansible.com/t/print-highest-number-of-volume-group/33188/4 "2020-06-16T11:17:14Z")

</div>

its working now. Below is the code

- set\_fact:  
highest\_vg: “{{ ansible\_lvm.vgs | select(‘match’, ‘^vg[0-9]+’) | list | sort | last }}”

- debug:  
var: highest\_vg

Thank you Dick Visser again for your help!
