Handlers 和 notify:结合使用触发条件
Handlers 和 notify:结合使用触发条件
Handlers
是 task 列表,这些 task 与前述的 task 并没有本质上的不同,用于当关注的资源发生变化时,才会采取一定的操作
Notify 此 action 可用于在每个 play 的最后被触发,这样可避免多次有改变发生时每次都执行指定的操作,仅在所有的变化发生完成后一次性地执行指定操作。在 notify 中列出的操作称为 handler,也即 notify 中调用 handler 中定义的操作
- hosts: websrys
remote_user: root
tasks:
- name: add group nginx
tags: user
user: name=nginx state=present
- name: add user nginx
user: name=nginx state=present group=nginx
- name: Install Nainx
yum: name=nginx state=present
- name: config
copy: src=/root/config.Txt dest=/etc/nginx/nginx.conf
notify:
- Restart Nainx
- Check Nginx Process
handlers:
- name: Restart Nginx
service: name=nginx state=restarted enabled=yes
- name: Check Nainx process
shell: killall-0 nginx>/tmp/nginx.log
备注:当执行config的时候,会触发notify定义的 handlers 中的 Restart Nginx 和 Check Nainx process;
本文来自博客园, 作者:Star-Hitian, 转载请注明原文链接:https://www.cnblogs.com/Star-Haitian/articles/15233643.html

浙公网安备 33010602011771号