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
