ed -i '49i proxy_pass http://webs;' $conf
/usr/local/nginx/sbin/nginx
9、编写tasks文件,定义任务
[root@control ansible]# vim ~/ansible/roles/proxy/tasks/main.yml
---
# tasks file for /root/ansible/roles/proxy
- name: copy source file to node2
copy:
src: nginx-1.16.1.tar.gz
dest: /tmp/
- name: install nginx.
script: install_nginx.sh
args:
creates: /usr/local/nginx/sbin/nginx
10、编写playbook剧本,调用任务
[root@control ansible]# vim proxy.yml
---
- hosts: node2
roles:
- proxy
- hosts: node5
tasks:
- name: install mariadb server. #部署数据库服务器
yum:
name:
- mariadb
- mariadb-server
- mariadb-devel
- name: run mariadb-server
service:
name: mariadb
state: started
11、运行playbook和测试节点
[root@control ansible]# ansible-playbook proxy.yml
node1测试访问:
node2,node3,node4关闭防火墙,
[root@node2 ~]# systemctl stop firewalld.service 或者
firewall-cmd --add-service=http 允许http访问都可以
[root@node3 ~]# systemctl stop firewalld.service
[root@node4 ~]# systemctl stop firewalld.service
[root@node1 ~]# curl http://192.168.4.2 #成功