Ansible Nginx Management configuration file

Source: Internet
Author: User
Tags vars

L most of the time in a production environment, you need to manage the configuration files, and the installation packages are only used when initializing the environment. Let's write a playbook to manage nginx configuration files.

L mkdir-p/etc/ansible/nginx_config/roles/{new,old}/{files,handlers,vars,tasks}

LwhichNewTo be used for the update, Oldused for rollback,FilesBelow isnginx.confand thevhostsdirectory,handlersRestartNginxCommands for services

L for rollback, you need to perform a Playbook before you back up the old configuration, so for the old configuration file management must be strict, must not casually to modify the configuration of the online machine, and to ensure that New/files The following configuration is consistent with the configuration on the line

L first put nginx.conf and the vhosts The catalog is placed in Files directory below

L cd/usr/local/nginx/conf/

L cp-r nginx.conf vhosts/etc/ansible/nginx_conf/roles/new/files/

L vim/etc/ansible/nginx_config/roles/new/vars/main.yml// Defining Variables

L Nginx_basedir:/usr/local/nginx

L vim/etc/ansible/nginx_config/roles/new/handlers/main.yml// To define a reload Nginx Service

L -Name:restart Nginx

L Shell:/etc/init.d/nginx Reload

L vim/etc/ansible/nginx_config/roles/new/tasks/main.yml// This is the core mission.

L -name:copy conf file

L copy:src={{Item.src}} dest={{nginx_basedir}}/{{item.dest}} backup=yes owner=root group=root mode=0644

L With_items:

L -{src:nginx.conf, dest:conf/nginx.conf}

L -{src:vhosts, dest:conf/}

L Notify:restart Nginx

L vim/etc/ansible/nginx_config/update.yml// Finally, define the total Portal Configuration

L ---

L -Hosts:testhost

L User:root

L roles:

L -New

L Execution: ansible-playbook/etc/ansible/nginx_config/update.yml

L and Roll back the backup.yml corresponding to the Roles to be Old

L rsync-av/etc/ansible/nginx_config/roles/new//etc/ansible/nginx_config/roles/old/

L The rollback operation is to overwrite the old configuration and reload Nginx Service


Ansible Nginx Management configuration file

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.