Ansible Playbook handlers 语句

…衆ロ難τιáo~ 提交于 2020-03-11 09:39:00

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   

 

 

 

 

    

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!