ansible handler模块,ansiblehandler


---
- include: config.yml

- name: Flush handlers
  meta: flush_handlers

用于在task完成后立即执行 task中的handler

notify与handler结合

notify多个handler使用关键字listen

(一)单个playbook中使用notify和handler

---
- name: test.yml just for test  
  hosts: testserver  
  vars:    
      region: ap-southeast-1  
  tasks:    
      - name: template configuration
        file      template: src=template.j2 dest=/etc/foo.conf      
  notify:          
      - restart memcached          
      - restart apache  
  handlers:    
        - name: restart memcached      
          service: name=memcached state=restarted    
        - name: restart apache      
          service: name=apache state=restarted

 

(二)在roles中使用

roles

    ├── dbservers

    │   ├── files

    │   ├── handlers

    │   ├── meta

    │   ├── tasks

    │   ├── templates

    │   └── vars

    └── webservers

        ├── files

        ├── handlers

        ├── meta

        ├── tasks

        ├── templates

        └── vars

handler文件夹下main.yml文件

task文件夹,deploy.yml    

如有侵权请联系立即删除

出处:http://www.zsythink.net/archives/2624

相关内容

    暂无相关文章