Playbook handlers使用

Handlers 模块的使用

---
- name: template index.html
  hosts: localhost
  tasks:
    - template:
src: /tmp/index.html
dest: /var/www/html/index.html
notify:
- restart httpd

  handlers:
    - name: restart httpd
service:
name: httpd
state: restared

playbook 是幂等的,当前一个Task被执行后 再执行handlers内的任务 就会实现只有更改完配置文件 才重启服务的效果,对没有更改配置文件的服务 不影响! 

handlers 需要和Tasks对齐

原文地址:https://www.cnblogs.com/oscarli/p/13153143.html