Ansible Playbook handlers 語句


handlers 用法如下,表示當 tasks 執行成功之后再執行 handlers,相當於 shell 中的 && 用法,如果 tasks 執行失敗是不會執行 handlers 語句的

[root@localhost ~]$ cat handlers.yml 
---
- name: handlers test
  hosts: 192.168.119.134
  user: root
  tasks:
    - name: copy file
      copy: src=/etc/passwd dest=/tmp/aaa.txt
      notify: test handlers                         # 這里要指定執行哪個handlers,對應下面的name,我們可以定義多個handlers,通過 handlers name 來識別不同的handlers
  handlers:                                         # 表示如果拷貝文件成功,就使用 shell 模塊執行 echo "abc" >> /tmp/aaa.txt 命令
    - name: test handlers 
      shell: echo "abc" >> /tmp/aaa.txt   

 

 

 

 

    


免責聲明!

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



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