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-2025 CODEPRJ.COM