Something like this would do the trick:

In this case I'm using loop0 instead of sdb.
If loop0 size is higher than 2 GB (assuming no conversion to MB, that would
be great too).
It will set lv_size var to 500M, and thar value will be used in lvol task
otherwise it will use default lv size which is 400M.

HTH



- hosts: localhost
become: True
gather_facts: False
vars:
disk: loop0
vg_name: vgname
lv_name: lvname
default_lv_size: 400M
tasks:
- name: Collect hardware facts
setup:
gather_subset:
- hardware

- name: Register {{ disk }} size
set_fact:
secondary_disk_size: hostvars[inventory_hostname].ansible_devices['{{ disk
}}'].size.split(' ')[0]

- name: Set lv size
set_fact:
lv_size: "500M"
when:
- secondary_disk_size | int > 2

- name: Create {{ lv_name }} lv
lvol:
vg: "{{ vg_name }}"
lv: "{{ lv_name }}"
size: "{{ lv_size | d (default_lv_size) }}"
active: yes
force: no
state: present


El lun, 25 ene 2021 a las 15:41, ursa Brown (<ursabear...@gmail.com>)
escribió:

> Can you please show me how to do that? will this show an error? before
> creating the LVM?
>
> On Monday, January 25, 2021 at 8:38:24 AM UTC-6 jruar...@gmail.com wrote:
>
>> You can fetch secondary disk size and set the lvm size depending on it.
>> This is what I would do in your case:
>>
>>    - Set default lvm size to a safe value that you know all your hosts
>>    will meet. ie : 20G
>>    - Fetch secondary disk size. If it's 50G or higher overwrite default
>>    lvm size to 40G
>>
>> Regards
>>
>>
>>
>>
>>
>>
>> El lun, 25 ene 2021 a las 15:27, ursa Brown (<ursab...@gmail.com>)
>> escribió:
>>
>>> I have hosts that has 50G and 30G of SDB or disk2..
>>> My playbook only works if hosts has SDB is 50G, then it has no problem
>>> creating  the 40G.
>>>
>>> But it throwing errros because some hosts has 30G of SDB.
>>>
>>> I want my playbook to still run, if the SB has only 30G then it will
>>> say, not enough disk, then will create a 20G.
>>> If the hosts has 50G, it will create the 40G lvm.
>>>
>>> Thank you
>>>
>>> On Monday, January 25, 2021 at 8:22:31 AM UTC-6 Antony Stone wrote:
>>>
>>>> On Monday 25 January 2021 at 15:15:56, ursa Brown wrote:
>>>>
>>>> > I got 2 hosts,
>>>> > one has 50G and the other one has 30G.
>>>> > I have no problem creating a 40G LVM on the hosts that has 50G. But
>>>> how can
>>>> > I make my ansible script if the hosts has 30G. It will say not enough
>>>> space
>>>> > then create 20G of lvm instead.
>>>>
>>>> Are you saying that you expect Ansible to create a 40Gb Logical Volume
>>>> on a
>>>> machine which has only 30Gb capacity?
>>>>
>>>> If not, please explain with a little more detail what you are trying to
>>>> get
>>>> Ansible to do.
>>>>
>>>>
>>>> Regards,
>>>>
>>>>
>>>> Antony.
>>>>
>>>> --
>>>> René Descartes walks in to a bar.
>>>> The barman asks him "Do you want a drink?"
>>>> Descartes says "I think not," and disappears.
>>>>
>>>> Please reply to the list;
>>>> please *don't* CC me.
>>>>
>>> --
>>> 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/f2252d83-0154-4413-8e04-3cec6c4c0b84n%40googlegroups.com
>>> <https://groups.google.com/d/msgid/ansible-project/f2252d83-0154-4413-8e04-3cec6c4c0b84n%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>> --
> 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-project+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/1f544b77-bc5a-4544-9f13-05a53fcc736fn%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/1f544b77-bc5a-4544-9f13-05a53fcc736fn%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
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-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAFtje5PMO2bjETpOa5DkV1%3Du38LT4sEdqViktjAVX42fGSSz%2BQ%40mail.gmail.com.

Reply via email to