Ansible Notify与Handler组合

Notify所在的Task状态为Changed时触发Handler Task, Handler与普通的Task没有任何区别。

 

示例 修改Apache配置后,重启Apache服务

---
- name: stup web server
  hosts: dev
  tasks:- name: copy apache index.html
      copy:
        src: index.html
        dest: /var/www/html/index.html
      notify:
        - restart httpd  # 调用handler,只有在该Task状态为Change时才会触发Handler。

  handlers:
    - name: restart httpd
      service:
        name: httpd
        enabled: true
        state: restarted

 

你可能感兴趣的:(Ansible Notify与Handler组合)