使用角色 apache

  1. 建立 playbook apache.yml,群組 webservers 使用角色 apache。
    [deyu1@kvm19 ansible]$ vim apache.yml
    [deyu1@kvm19 ansible]$ cat apache.yml 
    ---
    - name: use role
      hosts: webservers
      roles:
      - apache
    
  2. 執行 playbook apache.yml,成功完成任務。
    [deyu1@kvm19 ansible]$ ansible-playbook apache.yml 
    
    PLAY [use role] ****************************************************************
    
    TASK [Gathering Facts] *********************************************************
    ok: [kvm14]
    ok: [kvm13]
    
    TASK [apache : install the latest version of Apache] ***************************
    changed: [kvm14]
    changed: [kvm13]
    
    TASK [apache : Start service httpd] ********************************************
    changed: [kvm14]
    changed: [kvm13]
    
    TASK [apache : firewalld] ******************************************************
    changed: [kvm14]
    changed: [kvm13]
    
    TASK [apache : Template a file] ************************************************
    changed: [kvm14]
    changed: [kvm13]
    
    PLAY RECAP *********************************************************************
    kvm13 : ok=5 changed=4 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
    kvm14 : ok=5 changed=4 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
    
  3. 測試連線。
    [deyu1@kvm19 ansible]$ curl http://kvm14/
    Welcome to kvm14.deyu.wang on 192.168.122.14
    [deyu1@kvm19 ansible]$ curl http://kvm13/
    Welcome to kvm13.deyu.wang on 192.168.122.13