1. 程式人生 > >ansible-playbook

ansible-playbook

service yum hand defaults cli use tar 結構 div

語言格式:yml

  單個yml文件示例:

---
 - hosts: webservers          #主機組
   vars:                             ##變量設置
     http_port: 80
     max_clients: 200
   remote_user: root
   tasks:                            ###主要任務
   - name: ensure apache is at the latest version
     yum: pkg=httpd state=latest
   - name: write the apache config file
     template: src=/srv/httpd.j2 dest=/etc/httpd.conf
     notify:                                 ##條件觸發
     - restart apache                      ##重啟服務
   - name: ensure apache is running
     service: name=httpd state=started
   handlers:                                 ##在發生改變時執行的操作
     - name: restart apache
       service: name=httpd state=restarted

‘notify’ 下列出的即是 handlers.

 

ansible-playbook基本介紹 

項目結構:

技術分享圖片
site.yml
webservers.yml
fooservers.yml
roles/
   common/
     files/
     templates/
     tasks/
     handlers/
     vars/
     defaults/
     meta/
   webservers/
     files/
     templates/
     tasks/
     handlers
/ vars/ defaults/ meta/
View Code

ansible-playbook