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
###########################################################