playbook核心元素之 --> handlers 介绍
Handlers:由特定条件触发的Tasks;
[root@ansible ~]# vim test2.yaml - hosts: centos7 remote_user: root tasks: - name: install httpd yum: name=httpd state=latest - name: copy config file copy: src=/root/httpd.conf dest=/etc/httpd/conf/httpd.conf notify: restart httpd service --> 和notify配合使用即可 - name: start httpd service service: name=httpd state=started handlers: - name: restart httpd service service: name=httpd state=restarted
[root@ansible ~]# ansible-playbook test2.yaml
[root@ansible ~]# vim httpd.conf Listen 8080 --> 修改httpd的配置文件,将监听的端口修改为8080
[root@ansible ~]# ansible-playbook test2.yaml
[root@node7-1 ~]# netstat -tlnp | grep "httpd" tcp6 0 0 :::8080 :::* LISTEN 5908/httpd //对应节点上的httpd已经成功监听在8080端口了
转载于:https://blog.51cto.com/sixijie123/1878060