Sample code for batch deployment of Nginx with Ansible

Sample code for batch deployment of Nginx with Ansible

1.1 Copy the nginx installation package and installation script to the client and install the script

vim /ansible/roles/nginx/tasks/nginx.yml

- name: copy nginx_tar_gz to client
 copy: src=nginx-1.8.0.tar.gz dest=/tmp/nginx-1.8.0.tar.gz
- name: copy install_shell to client
 copy: src=install_nginx.sh dest=/tmp/install_nginx.sh
- name: install nginx
 shell: /bin/bash /tmp/install_nginx.sh

1.2 Nginx installation script

vim /ansible/roles/nginx/files/install_nginx.sh

#!/bin/bash
yum -y install zlib zlib-devel openssl openssl-devel pcre-devel
groupadd -r nginx
useradd -s /sbin/nologin -g nginx -r nginx
cd /tmp
tar xf nginx-1.8.0.tar.gz;cd nginx-1.8.0
mkdir /application/nginx/;chown nginx.nginx /application/nginx/
./configure \
--prefix=/usr \
--sbin-path=/usr/sbin/nginx \
--conf-path=/etc/nginx/nginx.conf \
--error-log-path=/var/log/nginx/error.log \
--pid-path=/application/nginx/nginx.pid \
--user=nginx \
--group=nginx \
--with-http_ssl_module
make && make install
egrep -v "#|^$" /etc/nginx/nginx.conf >/etc/nginx/nginx.conf.bak
rm -rf /etc/nginx/nginx.conf
mv /etc/nginx/nginx.conf.bak /etc/nginx/nginx.conf
sed -i "/^\s*index / i proxy_pass http://localhost:8080;" /etc/nginx/nginx.conf
/usr/sbin/nginx

1.3 Execute ansible command

cd /ansible
ansible-playbook nginx.yml --syntax-check #Check syntax ansible-playbook nginx.yml #Execute

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

<<:  Detailed explanation of Nodejs array queue and forEach application

>>:  Mysql inner join on usage examples (must read)

Recommend

Summary of 4 ways to add users to groups in Linux

Preface Linux groups are organizational units use...

How to optimize the slow Like fuzzy query in MySQL

Table of contents 1. Introduction: 2. The first i...

Use Navicate to connect to MySQL on Alibaba Cloud Server

1. First enter the server's mysql to modify p...

MySQL uses custom sequences to implement row_number functions (detailed steps)

After reading some articles, I finally figured ou...

Sample code for implementing markdown automatic numbering with pure CSS

The origin of the problem The first time I paid a...

Vue implements video upload function

This article example shares the specific code of ...

React's component collaborative use implementation

Table of contents Nesting Parent-child component ...

How to clear floating example code in css

Overview The framework diagram of this article is...

Solutions to MySql crash and service failure to start

I have been in contact with PHP for so long, but ...

Pure HTML+CSS to achieve Element loading effect

This is the effect of the Element UI loading comp...