Use Ansible to publish Tomcat service in CentOS 7
1. About ansible
Ansible is an Open Server Deployment Tool for Python.
Using yum for configuration is very simple and easy to learn.
2. Install
Http://docs.ansible.com/ansible/intro_installation.html
Refer to the official website and run yum install on CentOS 7.
sudo yum install ansible
3. Create tomcat and deploy yml
The ansible module has many super Conveniences:
Http://docs.ansible.com/ansible/list_of_all_modules.html
Tomcat directly deletes all the folders in webapps during deployment.
Deploy the tool directly to the webapps/ROOT folder during deployment.
Because webapps contain tomcat admin management and some demos, they are useless, and there are security risks. They can be deleted directly.
Edit admin. yml, where tomcat-admin must be configured in hosts.
-Name: install tomcat admin hosts: tomcat-admin sudo: True vars: war_file:/local-data-dir/admin. war # local file atat_root:/remote-data-dir/tomcat/webapps/ROOT # deployed remote ROOT directory tasks:-name: stop tomcat. action: shell {tomcat_root }}/.. /.. /bin/catalina. sh stop-force-name: rm ROOT. file: state: absent dest: "{tomcat_root}"-name: mkdir ROOT. file: state: directory dest: "{tomcat_root}" owner: root group: root mode: 755-name: unzip war. unarchive: src: "{war_file}" dest: "{tomcat_root}" copy: yes-name: start tomcat. action: shell {tomcat_root }}/.. /.. /bin/catalina. sh start
Five Commands are used to solve the problem of tomcat going online.
1. action: shell stops tomcat because the tomcat directory is directly set to the root directory. A././bin is added.
2. Delete the ROOT folder and use file: state: absent to prevent file Deletion errors.
3. Use the unarchive command, copy: yes to directly copy the local file to a remote location, and decompress the file and delete the file. Several repeated operations are saved. Step by step.
Refer:
Http://docs.ansible.com/ansible/unarchive_module.html
Run ansible-playbook admin. yml to deploy the application. Very simple.
4. Summary
Ansible uses yml, which is very simple to learn.
I hate writing shell, and I use python to deploy some duplicate code.
Debugging is also very troublesome during deployment. ansible is very good, and debugging is easy to add-debug: labels.
Use Ansible to efficiently deliver Docker containers
Batch manage remote servers using Ansible
Ansible installation configuration and simple use
Install and use the automation tool Ansible in CentOS 7
Functions and usage of Ansible and Docker
Ansible batch build LAMP Environment
Ansible: a configuration management and IT automation tool
Ansible details: click here
Ansible: click here
This article permanently updates the link address: