print highest number of volume group

15 views
Skip to first unread message

ravi teja

unread,
Jun 15, 2020, 4:25:39 PM6/15/20
to Ansible Project
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]

TASK [debug] ***************************************************************************************************************************************************************
ok: [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]

TASK [debug] ***************************************************************************************************************************************************************
ok: [rhel7.lab.com] =>
  highest.stdout: vg09

PLAY RECAP *****************************************************************************************************************************************************************
rhel7.lab.com              : ok=5    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0
Thank you.

Dick Visser

unread,
Jun 15, 2020, 5:18:34 PM6/15/20
to ansible...@googlegroups.com
Try:


"{{ ansible_lvm.lvs | select('match', '^vg[0-9]+') | list | sort | last }}"
> --
> You received this message because you are subscribed to the Google Groups "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/cb370286-125b-4f2d-8faf-0a975008b40co%40googlegroups.com.



--
Dick Visser
Trust & Identity Service Operations Manager
GÉANT

ravi teja

unread,
Jun 15, 2020, 6:57:08 PM6/15/20
to Ansible Project
Thank you Dick Visser. It’s working for me.

ravi teja

unread,
Jun 16, 2020, 7:17:14 AM6/16/20
to Ansible Project
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!
Reply all
Reply to author
Forward
0 new messages