ansible-构建NGINX
playbook编写编译安装NGINX剧本
剧本如下:
[dwchensenwen@vms20 script]$ cat nginx.yaml --- - hosts: test become: yes become_method: sudo tasks: - name: 安装依赖包 yum: name={{ item }} state=latest with_items: - pcre-devel - openssl-devel - name: 创建一个管理nginx进程的虚拟用户 user: name=www shell=/sbin/nologin/ state=present - name: 创建目录 command: > mkdir -p /server/tools mkdir -p /application - name: 下载nginx软件包 get_url: url: http://nginx.org/download/nginx-1.12.2.tar.gz dest: /server/tools/nginx-1.12.2.tar.gz mode: 0755 - name: 解压NGINX软件包 command: > tar -C /server/tools -xvf /server/tools/nginx-1.12.2.tar.gz - name: 编译安装NGINX shell: cd /server/tools/nginx-1.12.2;./configure --prefix=/application/nginx-1.12.2 --user=www --group=www --with-http_ssl_module --with-http_stub_status_module;make && make install - name: nginx程序软件创建链接目录 file: src=/application/nginx-1.12.2 dest=/application/nginx state=link - name: 启动NGINX程序服务 shell: /application/nginx/sbin/nginx
运行结果:
查看远端NGINX服务
本地浏览器访问: