If you are looking to install apache tomcat instances, consider using Ansible as a slap-up way.

Ansible is an agentless automation tool that manages machines over the SSH protocol by default. Once installed, Ansible does not add a database, and there volition be no daemons to outset or keep running.

With Ansible, you can create an ansible playbook and employ information technology to deploy dozens of tomcat in one get. In this tutorial, you lot will acquire how to install apache tomcat using Ansible. Allow's become started.

Table of Content

  1. Prerequisites
  2. Building tomcat Ansible-playbook on the Ansible Controller
  3. Running Ansible-playbook on the Ansible Controller
  4. Tomcat files and Tomcat directories on a remote node
  5. Conclusion

Prerequisites

This post will be a step-by-step tutorial. If you'd like to follow forth, be sure yous take:

  • An Ansible controller host. This tutorial will exist using Ansible v2.9.18.
    • In case information technology is not installed please refer: Install Ansible on UbuntuMachine
  • A remote Linux computer to examination out the tomcat installation. This tutorial uses Ubuntu xx.04.3 LTS every bit the remote node.
  • An inventory file and one or more hosts are configured to run Ansible commands and playbooks. The remote Linux calculator is chosen webserver, and this tutorial uses an inventory group called web.

Ensure your remote machine IP address is inside /etc/ansible/hosts ( either ane remote machine or ascertain it as a group)

Building tomcat Ansible-playbook on the Ansible Controller

Ansible is an automation tool used for deploying applications and systems easily; information technology could exist Cloud, Services, orchestration, etc. Ansible uses YAML Language to build playbooks which are finally used to deploy or configure the required modify. To deploy tomcat, let'south movement ahead and create the ansible-playbook.

  • SSH or login into your any Linux machine.
  • Create a file named my_playbook3.yml inside /etc/ansible folder and paste below code.

The below playbook contains all the tasks to install tomcat on the remote node. The first task is to update your arrangement packages by using the apt command, farther creating tomcat user and group. The next task is to install java, install tomcat, and create necessary folders and permissions for the tomcat directory.

--- - name: Install Apache Tomcat10 using ansible   hosts: webserver   remote_user: ubuntu   become: true   tasks:     - proper noun: Update the Arrangement Packages       apt:         upgrade: yes         update_cache: yes      - name: Create a Tomcat User       user:         name: tomcat      - proper noun: Create a Tomcat Group       group:         name: tomcat      - proper name: Install JAVA       apt:         name: default-jdk         state: present       - name: Create a Tomcat Directory       file:         path: /opt/tomcat10         possessor: tomcat         group: tomcat         style: 755         recurse: yes      - name: download & unarchive tomcat10        unarchive:         src: https://mirrors.estointernet.in/apache/tomcat/tomcat-10/v10.0.4/bin/apache-tomcat- 10.0.four.tar.gz         dest: /opt/tomcat10         remote_src: yes         extra_opts: [--strip-components=1]      - name: Alter ownership of tomcat directory       file:         path: /opt/tomcat10         owner: tomcat         group: tomcat         mode: "u+rwx,k+rx,o=rx"         recurse: yes         country: directory      - name: Re-create Tomcat service from local to remote       copy:         src: /etc/tomcat.service         dest: /etc/systemd/system/         style: 0755      - name: Get-go and Enable Tomcat 10 on sever       systemd:         name: tomcat         country: started         daemon_reload: true                 

Running Ansible-playbook on the Ansible Controller

Earlier in the previous section, you lot created the ansible-playbook, which is great, but it is non doing much unless yous deploy it. To deploy the playbook using the ansible-playbook command.

Assuming y'all are logged into Ansible controller:

  • Now run the playbook using the beneath ansible-playbook command.
ansible-playbook my_playbook3.yml                

As you can see below, all the tasks are successfully completed; if the status of TASK shows ok, that means the task was already completed; else, for changed status, Ansible performs the task on the remote node.

Running the ansible-playbook in the Ansible controller host
Running the ansible-playbook in the Ansible controller host
  • Next, verify remote motorcar if Apache Tomcat is installed successfully and started use the below command.
systemctl status tomcat  service tomcat status                
Verifying the tomcat service on the remote node
Verifying the tomcat service on the remote node
  • Also y'all can verify past running procedure command.
ps -ef | grep tomcat ps -aux | grep tomcat                
Checking the tomcat process
Checking the tomcat process
Checking the tomcat process
Checking the tomcat process

Tomcat files and Tomcat directories on a remote node

Now that you have successfully installed the tomcat on the remote node and verified the tomcat service, it is as important to bank check the tomcat files created and the purpose of each of them.

  • Firstly all the tomcat files and tomcat directories are stored under <tomcat-installation-directory>/*.

Your installation directory is represented by environmental variable$CATALINA_HOME

  • The tomcat directory and files should be owned by user tomcat
  • The tomcat user should be member of tomcat group.
Verify all files of tomcat
Verify all files of tomcat
  • <tomcat-installation-directory>/bin: This directory consists of startup and shutdown scripts (startup.sh and shutdown.sh) to run or terminate the tomcat directly without using the tomcat service configured.
Verify installation directory of tomcat
Verify installation directory of tomcat
  • <tomcat-installation-directory>/conf: This is very crucial directory where tomcat keeps all its configuration files.
Tomcat configuration directory
Verify Tomcat configuration directory
  • <tomcat-installation-directory>/logs: In case you get whatever errors while running your tomcat so you can look at your safeguard ie. logs , tomcat creates its own logs under this directory.
Tomcat logs directory
Verify Tomcat logs directory
  • <tomcat-installation-directory>/webapps: This is the directory where you place your code such as .state of war and run your applications. It is highly recommended to stop tomcat and and so deploy your application inside this directory and so start tomcat.
Tomcat Code directory
Verify Tomcat Code directory

Conclusion

In this tutorial, nosotros covered in-depth how tin can you install Apache Tomcat ten on the ubuntu xviii.0 version using Ansible controller and finally discussed files and directories which are most important for whatever Apache tomcat admins and developers.

If you wish to run your application on lightweight and easily, Apache Tomcat is your friend.