一 、handlers和notify結合觸發條件
handlers(觸發器): 定義一些task列表,與之前劇本中task沒有關系,只有資源發送變化才會采取一定的操作
notify:notify中調用handler中定義的操作
二、修改配置文件,重啟服務
1、yum安裝httpd
[root@linux-node1 ~]# tree ansible/ ansible/ ├── files │ └── httpd.conf ├── file.yaml └── httpd.yaml
[root@linux-node1 ansible]# cat httpd.yaml
---
- hosts: date
remote_user: root
tasks:
- name: install httpd package
yum: name=httpd
- name: copy conf file
copy: src=files/httpd.conf dest=/etc/httpd/conf backup=yes
- name: start service
service: name=httpd state=started enabled=yes
2、修改配置文件端口8081,在次執行,httpd服務沒有重啟
[root@linux-node1 ansible]# cat httpd.yaml
---
- hosts: date
remote_user: root
tasks:
- name: install httpd package
yum: name=httpd
- name: copy conf file
copy: src=files/httpd.conf dest=/etc/httpd/conf backup=yes
notify: restart service
- name: start service
service: name=httpd state=started enabled=yes
handlers:
- name: restart service
service: name=httpd state=restarted


三、定義多個notify
