2017-10-11 handlers的使用

2017-10-11  本文已影响0人  EmptyBottl_520d
---
- hosts: centos6
  tasks:
    - name: see hostname
      shell: ifconfig
    - name: copy_test
      copy: src=/root/iptables dest=/etc/sysconfig/iptables backup=yes
      notify:
        - restart iptables
  handlers:
    - name: restart iptables
      service: name=iptables state=restarted

handlers 任务需要 notify 来触发,notify所在的任务项 造成客户端系统文件改变的时候 才会触发notify.
一个play中的handlers只会被执行一次 最后执行.
Handlers 最佳的应用场景是用来重启服务,或者触发系统重启操作.除此以外很少用到了

tasks:
   - shell: some tasks go here
     notyfy:
         - handlers job name
   - meta: flush_handlers
   - shell: some other tasks
上一篇 下一篇

猜你喜欢

热点阅读