實例–debug

  1. 將 blklvfs2.yml 腳本的 hosts 改為 blancers,並存成 blklvfs3.yml。
    [deyu1@kvm19 ansible]$ vim blklvfs3.yml
    [deyu1@kvm19 ansible]$ grep hosts blklvfs3.yml
    - hosts: balancers
    
  2. blklvfs3.yml,增加 debug 除錯,當 vg fieldwork 不存在時印出客製化訊息 "Volume group does not exist"。
    [deyu1@kvm19 ansible]$ cat blklvfs3.yml
    ---
    - hosts: balancers 
      tasks:
      ......................    
      - ansible.builtin.debug:
          msg: Volume group does not exist
        when: ansible_lvm.vgs.fieldwork is undefined
    
  3. ansible-playbook 執行 blklvfs3.yml 腳本,因 kvm15 的 vg fieldwork 不存在,所以執行 debug 任務,列印客製化訊息 "Volume group does not exist"。
    [deyu1@kvm19 ansible]$ ansible-playbook blklvfs3.yml
    
    PLAY [balancers] ****************************************************************
    
    TASK [Gathering Facts] **********************************************************
    ok: [kvm15]
    
    TASK [Create a logical volume of 200m] ******************************************
    skipping: [kvm15]
    
    TASK [Create a ext4] ************************************************************
    skipping: [kvm15]
    
    TASK [ansible.builtin.debug] ****************************************************
    ok: [kvm15] => {
        "msg": "Volume group does not exist"
    }
    
    PLAY RECAP **********************************************************************
    kvm15 : ok=2  changed=0  unreachable=0  failed=0  skipped=2  rescued=0  ignored=0