ansible-play中關於標簽tages,handler,notify的使用


---
 - hosts: webser
   remote_user: root
 
  tasks:
  - name: install httpd package
    yum: name=httpd
    tages: inshttpd   #標簽,可以根據標簽執行某個指定動作 命令:ansible-playbook -t reshttpd httpd.yml
  - name: copy conf file
    copy: src=files/httpd.conf dest=/etc/httpd/conf backup=yes
    notify: 
     - restart service
     - check service
    #單個可以寫成一行:  notify: restart service
    #這邊的名稱需要跟handlers中的name保持一致,才能觸發handlers的動作,此處可以定義多個action,對應的handler處需要做多個以匹配
  - name: start service      
    service: name=httpd state=started enabled=yes
    tages: rshttpd    #多個標簽可以同時執行 命令:ansible-playbook -t inshttpd,rshttpd httpd.yml。另外,此處一系列動作可以定義成同一個標簽,當執行該標簽時,執行定義的一系列動作。
    
  handlers:
  - name: restart service
    service: name=httpd state=restarted  enabled=yes       #一個notify對應一個handler的action
  - name: checke service
    service: killall -0 httpd > /tmp/http.log

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM