Ansible Installing Nginx

Source: Internet
Author: User

First, create the home folder and each sub-folder

cd  /etc/ansible
mkdir nginx_install
mkdir  -p Nginx_install/roles/{common,install}

Mkdir-p/etc/ansible/nginx_install/roles/common/tasks

Cd/etc/ansible/nginx_install/roles/install

mkdir handlers files meta tasks templates VARs


Description: The roles directory has three roles, common for some preparation operations, install for nginx operation

There are several directories under each role, handlers the following is the action to take when a change occurs, usually with a change in the configuration file, to restart the service. Files for the installation of some documents, meta for the description of information, the role depends on the information, tasks inside is the core configuration file, templates usually save some configuration files, startup scripts and other template files, VARs under the defined variables

second, pre-installation preparation

You need to prepare the installation files in advance, as follows:

Pre-compile and install Nginx on a single machine, configure the startup script, configure the configuration file.

After installation, we need to pack the Nginx directory and put it under/etc/ansible/nginx_install/roles/install/files/, named Nginx.tar.gz

Launch scripts, configuration files are put under/etc/ansible/nginx_install/roles/install/templates

Then CD nginx_install/roles/

mkdir tasks
vim./COMMON/TASKS/MAIN.YML//content as follows
-name:install initializtion require software
yum:name={{Item}} state=installed
With_items:
-GCC
-Zlib-devel
-Pcre-devel

Iii. Defining variables

vim./install/vars/main.yml
nginx_user:www
nginx_port:80
Nginx_web_dir:/data/www
nginx_version:1.6.3

Iv. Copying related configuration files

Vim/etc/ansible/nginx_install/roles/install/tasks/copy.yml

-Name:copy Nginx Software

copy:src=nginx.tar.gz dest=/tmp/nginx.tar.gz Owner=root Group=root

-Name:uncompression Nginx Software

Shell:tar zxf/tmp/nginx.tar.gz-c/usr/local/

-Name:copy Nginx Start Script

Template:src=nginx Dest=/etc/init.d/nginx owner=root group=root mode=0755

-Name:copy Nginx Config

template:src=nginx.conf dest={{nginx_basedir}}/conf/owner=root group=root mode=0644

Create a user, start a service, delete a compressed package

VIM/ETC/ANSIBLE/NGINX_INSTALL/ROLES/INSTALL/TASKS/INSTALL.YML//content is as follows

-Name:create Nginx User

user:name={{Nginx_user}} state=present createhome=no Shell=/sbin/nologin

-Name:start Nginx Service

Service:name=nginx state=restarted

-Name:add Boot Start Nginx Service

Shell:chkconfig--level 345 Nginx on

-Name:delete Nginx compression files

Shell:rm-rf/tmp/nginx.tar.gz

VI. Create MAIN.YML and call copy and install

VIM/ETC/ANSIBLE/NGINX_INSTALL/ROLES/INSTALL/TASKS/MAIN.YML//content is as follows

-Include:copy.yml

-Include:install.yml

Seven

To define the total Portal configuration file

VIM/ETC/ANSIBLE/NGINX_INSTALL/INSTALL.YML//content is as follows

---

-Hosts:testhost

Remote_user:root

Gather_facts:true

Roles

-Common

-Install

VIII. implementation of the installation

Ansible-playbook/etc/ansible/nginx_install/install.yml

This article from "愺 Burgundy pounding his 豩" blog, declined reprint!

Ansible Installing Nginx

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.