我们前面配置了apache了,但是我们需要知道什么时候需要重启apache,这个时候我们就需要监控配置文件,也就是说,配置文件发生改变的时候,我们就要重启
这个,我们就用到了notify这个功能了,我另外一个博文也写了如何使用notify
http://www.503error.com/2016/ansible-playbook-notify/923.html
好,那么我现在增加一个handle
/root/ansible_home/roles/webservers/handlers
1 2 3 4 5 6 7 |
[root@zhizhang-a-master handlers]# cat main.yml --- - name: restart apache service: name=httpd state=restarted [root@zhizhang-a-master handlers]# |
然后,我们在task中的
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
[root@zhizhang-a-master tasks]# cat apache_vhost_conf.yml --- - debug: var="{{item.domainname}}" with_items: "{{ apache_vhosts_enabled }}" - name: create config for every site template: src=apache_vhost.conf.j2 dest=/etc/httpd/conf.d/{{item.domainname}}.conf with_items: "{{ apache_vhosts_enabled }}" notify: - restart apache [root@zhizhang-a-master tasks]# |
我们增加了 notify,此处注意,handlers中需要填写的name是httpd,不是apache
重新配置,搞定
Latest posts by Zhiming Zhang (see all)
- aws eks node 自动化扩展工具 Karpenter - 8月 10, 2022
- ReplicationController and ReplicaSet in Kubernetes - 12月 20, 2021
- public key fingerprint - 5月 27, 2021