實例–rescue

  1. 將 lvfs1.yml 腳本的 hosts 改為 test,並存成 lvfs2.yml。
  2. ansible-playbook 執行 lvfs2.yml 腳本,因 kvm12 的 vg 不足 200M,所以無法新增,所以執行 rescue 任務,列印客製化訊息 "Could not create logical volume of that size",並改新增 100M 的 lv。
    [deyu1@kvm19 ansible]$ ansible-playbook lvfs2.yml
    
    PLAY [test] ********************************************************************
    
    TASK [Gathering Facts] *********************************************************
    ok: [kvm12]
    
    TASK [Create a logical volume of 200m] *****************************************
    fatal: [kvm12]: FAILED! => {"changed": false, "err": "  Insufficient free space: 25 
    extents needed, but only 12 available\n", "msg": "Unable to resize test to 200m", "rc": 5}
    
    TASK [debug] *******************************************************************
    ok: [kvm12] => {
        "msg": "Could not create logical volume of that size"
    }
    
    TASK [Create a logical volume of 100m] *****************************************
    changed: [kvm12]
    
    TASK [Create a ext4] ***********************************************************
    changed: [kvm12]
    
    PLAY RECAP *********************************************************************
    kvm12 : ok=4 changed=2 unreachable=0 failed=0 skipped=0 rescued=1 ignored=0
    
  3. 登入 kvm12 查看 /dev/fieldwork/test 大小為 100M,且檔案格式為 ext4。
    [root@kvm12 ~]# lvdisplay /dev/fieldwork/test 
      --- Logical volume ---
      LV Path                /dev/fieldwork/test
      LV Name                test
      VG Name                fieldwork
      LV UUID                00btWc-eqJi-2Edq-e3EI-OACb-d7eP-jCbLbK
      LV Write Access        read/write
      LV Creation host, time kvm12.deyu.wang, 2020-04-01 20:13:13 +0800
      LV Status              available
      # open                 0
      LV Size                100.00 MiB
      Current LE             25
      Segments               1
      Allocation             inherit
      Read ahead sectors     auto
      - currently set to     8192
      Block device           253:2
       
    [root@kvm12 ~]# lsblk -f /dev/fieldwork/test
    NAME           FSTYPE LABEL UUID                                 MOUNTPOINT
    fieldwork-test ext4         a1ccbef7-ebd6-479c-8168-1dccb65464f5