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对齐

posted @ 2020-06-17 16:27  阿里云的奥斯卡  阅读(165)  评论(0编辑  收藏  举报