Try:

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


On Mon, 15 Jun 2020 at 22:25, ravi teja <[email protected]> wrote:
>
> 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.
>
> --
> 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 [email protected].
> 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

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAL8fbwPbYfsoubjVAE23PYsodEoPWbA1Sgm2yZK1bK_obbrjEw%40mail.gmail.com.

Reply via email to