Block is working as expected but

44 views
Skip to first unread message

Aris Aguirre

unread,
Feb 2, 2021, 4:27:21 PM2/2/21
to Ansible Project
Instead of throwing FATAL errors out  there, can we do something like? It will say "Volume group vgaris does not exist" if the VG doesnt exist,
and if it is like creating the 3g instead of 7G, it will say,  "insufficient space, will create the 3G"


My playbook:
###########################
---
- hosts: all
  name: Create right VG
  become: yes
  tasks:

  - name: Create VG now
    block:
    - name: Check 7G
      lvol:
         vg: vgaris
         lv: lvaris
         size: 7000M

    rescue:
    - name: Create a 3G
      lvol:
         vg: vgaris
         lv: lvaris
         size: 3000M



#################################





Current Output:
################################

$ ansible-playbook block.yml

PLAY [Create right VG] ****************************************************************************************************************************************************************************************

TASK [Gathering Facts] ****************************************************************************************************************************************************************************************
ok: [soctxlab06]
ok: [soctxrhprx01]
ok: [soctxseglbdev01]

TASK [Check 7G] ***********************************************************************************************************************************************************************************************
fatal: [soctxrhprx01]: FAILED! => {"changed": false, "err": "  Volume group \"vgaris\" not found\n  Cannot process volume group vgaris\n", "msg": "Volume group vgaris does not exist.", "rc": 5}
fatal: [soctxseglbdev01]: FAILED! => {"changed": false, "err": "  Volume group \"vgaris\" has insufficient free space (1279 extents): 1750 required.\n", "msg": "Creating logical volume 'lvaris' failed", "rc": 5}
changed: [soctxlab06]

TASK [Create a 3G] ********************************************************************************************************************************************************************************************
fatal: [soctxrhprx01]: FAILED! => {"changed": false, "err": "  Volume group \"vgaris\" not found\n  Cannot process volume group vgaris\n", "msg": "Volume group vgaris does not exist.", "rc": 5}
changed: [soctxseglbdev01]

PLAY RECAP ****************************************************************************************************************************************************************************************************
soctxlab06                 : ok=2    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0
soctxrhprx01               : ok=1    changed=0    unreachable=0    failed=1    skipped=0    rescued=1    ignored=0
soctxseglbdev01            : ok=2    changed=1    unreachable=0    failed=0    skipped=0    rescued=1    ignored=0


###########################################################

Dick Visser

unread,
Feb 2, 2021, 5:50:15 PM2/2/21
to ansible...@googlegroups.com
Although the docs on the size parameter don't mention a default behavior, they do mention accepting a percentage of VG/PVS/FREE: https://docs.ansible.com/ansible/latest/collections/community/general/lvol_module.html#parameter-size.
There is an example about it as well with "100%FREE":

This is what you are looking for (I think) - no need for trial and error.



--
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/8139b2d0-fae8-4871-855f-0f024eafb23en%40googlegroups.com.


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

Aris Aguirre

unread,
Feb 2, 2021, 9:44:19 PM2/2/21
to Ansible Project
Instead of failed for the server that doesnt have VG, it will show a message "no vg", instead of showing fatal error. is there a way to replace the fatal errors with debug message?

Dick Visser

unread,
Feb 3, 2021, 1:29:41 AM2/3/21
to ansible...@googlegroups.com
You should rewrite your playbook to test for the existing of such a vg, and only add an lv if the upper vg exists.

--
Sent from a mobile device - please excuse the brevity, spelling and punctuation.
Reply all
Reply to author
Forward
0 new messages