前提条件部署好jdk、tomcat
1.设置密钥服务
安装依赖
yum install -y http://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
安装ansible
yum -y install ansible
写入主机清单
vim /etc/ansible/hosts
ansible IP -m ping
2.#进入/usr/local/目录
mkdir nginx_test
cd nginx_test
上传nginx压缩包
tar zxf nginx-1.22.1.tar.gz
cd nginx-1.22.1/
cp conf/nginx.conf /usr/local/nginx_test
cd /usr/local/nginx_test
vim index.html
<h1>This is web1!<h1>
3.编写nginx.yml
vim nginx.yml
---
- hosts: 192.168.147.137
tasks:
- name: "推送Nginx源码包"
unarchive: src=nginx-1.22.1.tar.gz dest=/root/
- name: "安装依赖环境库"
yum: name=gcc,gcc-c++,pcre-devel,zlib-devel state=latest
- name: "安装Nginx"
shell: cd /root/nginx-1.22.1/ && ./configure && make && make install
- name: "推送配置文件"
copy: src=nginx.conf dest=/usr/local/nginx/conf/nginx.conf
- name: "推送测试页面"
copy: src=index.html dest=/usr/local/nginx/html/index.html
- name: "启动Nginx服务"
shell: netstat -ntl | grep -qw 80 || /usr/local/nginx/sbin/nginx
- hosts: 192.168.147.137
tasks:
- name: "推送Nginx源码包"
unarchive: src=nginx-1.22.1.tar.gz dest=/root/
- name: "安装依赖环境库"
yum: name=gcc,gcc-c++,pcre-devel,zlib-devel state=latest
- name: "安装Nginx"
shell: cd /root/nginx-1.22.1/ && ./configure && make && make install
- name: "推送配置文件"
copy: src=nginx.conf dest=/usr/local/nginx/conf/nginx.conf
- name: "推送测试页面"
copy: src=index.html dest=/usr/local/nginx/html/index.html
- name: "启动Nginx服务"
shell: netstat -ntl | grep -qw 80 || /usr/local/nginx/sbin/nginx
4.执行任务
#
用于执行
Ansible playbook
。
--syntax-check
参数表示仅检查
playbook
的语法
,
不执行其中的
任务。
ansible-playbook --syntax-check nginx.yml
#
执行任务
ansible-playbook nginx.yml

然后访问
192.168.147.137:80