實例–debug

  1. 將 lvfs2.yml 腳本的 hosts 改為 balancers,並存成 lvfs3.yml,增加 debug 除錯,當 vg fieldwork 不存在時印出客製化訊息 "Volume group does not exist"。
    [deyu1@kvm19 ansible]$ cat lvfs3.yml
    ---
    - hosts: balancers 
      tasks:
      ......................    
      - debug:
          msg: Volume group does not exist
        when: ansible_lvm.vgs.fieldwork is undefined
    
  2. ansible-playbook 執行 lvfs3.yml 腳本,因 kvm15 的 vg fieldwork 不存在,所以執行 debug 任務,列印客製化訊息 "Volume group does not exist"。
    [deyu1@kvm19 ansible]$ ansible-playbook lvfs3.yml
    
    PLAY [balancers] ***************************************************************
    
    TASK [Gathering Facts] *********************************************************
    ok: [kvm15]
    
    TASK [Create a logical volume of 200m] *****************************************
    skipping: [kvm15]
    
    TASK [Create a ext4] ***********************************************************
    skipping: [kvm15]
    
    TASK [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