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