Install Apache Tomcat 9 on Debian 10 using Ansible
Apache Tomcat is a free, open source HTTP server designed to serve Java web pages. Tomcat is an implementation of Java Servlet, JavaServer Pages, Java Expression Language and Java WebSocket technologies. It is widely deployed and supports a variety of mission-critical web applications around the world. This tutorial will discuss how to easily install Tomcat on Debian 10 Linux using Ansible.
The standard method for installing Tomcat on a Linux system (such as Debian) is manual and time-consuming. I wrote an Ansible role to simplify the process. A link to the Github project is shared below.
I will introduce the steps to install Tomcat in this role on a Debian 10 system.
Step 1: Install Ansible
The main dependency on your workstation is Ansible. Install Ansible on your Linux system using the following share command.
###### CentOS ###### sudo yum -y install epel-release && sudo yum -y install ansible ###### Fedora ###### sudo dnf -y install ansible ###### Ubuntu / Linux Mint ###### sudo apt-get install -y software-properties-common sudo apt-add-repository --yes --update ppa:ansible/ansible sudo apt-get update sudo apt-get install -y ansible ###### Debian ###### sudo apt-get install -y software-properties-common echo "deb http://ppa.launchpad.net/ansible/ansible/ubuntu trusty main" | sudo tee /etc/apt/sources.list.d/ansible.list sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 93C4A3FD7BB9C367 sudo apt update sudo apt install ansible ###### Arch/Manjaro ###### $ sudo pacman -S ansible ###### macOS ###### sudo easy_install pip sudo pip install ansible
Confirm that the installation is correct:
$ ansible --version ansible 2.9.2 config file = /etc/ansible/ansible.cfg configured module search path = [u'/home/debian/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules'] ansible python module location = /usr/lib/python2.7/dist-packages/ansible executable location = /usr/bin/ansible python version = 2.7.16 (default, Apr 6 2019, 01:42:57) [GCC 8.3.0]
Step 2: Clone the Ansible role from Github
The role of tomcat is Publicly available on Github Used to. Clone it to your workstation.
cd /tmp/
git clone https://github.com/jmutai/tomcat-ansible.git
cd tomcat-ansible
- Update your inventory, for example:
$ vim hosts
[tomcat-nodes]
192.168.20.55 # Add Server IP address, one line per server
- Update variables in script file-set Tomcat version, remote user and Tomcat UI access credentials
$ vim tomcat-setup.yml
- name: Tomcat deployment playbook
hosts: tomcat-nodes # Inventory hosts group / server to act on
become: yes # If to escalate privilege
become_method: sudo # Set become method
remote_user: root # Update username for remote server
vars:
tomcat_ver: 9.0.30 # Tomcat version to install
ui_manager_user: manager # User who can access the UI manager section only
ui_manager_pass: [email protected] # UI manager user password
ui_admin_username: admin # User who can access bpth manager and admin UI sections
ui_admin_pass: [email protected] # UI admin password
roles:
- tomcat
Begin_method is required when using a non-root remote user.
become: yes
become_method: sudo
Step 3: Install Apache Tomcat 9 on Debian 10 using Ansible
After updating all values, you can run the script against the node.
Script executed as root-use ssh key:
$ ansible-playbook -i hosts tomcat-setup.yml
Script executed as root user-password:
$ ansible-playbook -i hosts tomcat-setup.yml --ask-pass
Script executed as sudo user-password:
$ ansible-playbook -i hosts tomcat-setup.yml --ask-pass --ask-become-pass
Script executed as sudo user-using ssh key and sudo password:
$ ansible-playbook -i hosts tomcat-setup.yml --ask-become-pass
Script executed as sudo user-using ssh key and passwordless sudo:
$ ansible-playbook -i hosts tomcat-setup.yml --ask-become-pass
Successful installation output will display output similar to the following.
PLAY [Tomcat deployment playbook] **********************************************************************************************************************
TASK [Gathering Facts] *********************************************************************************************************************************
ok: [deb01]
TASK [tomcat : Add the OS specific variables] **********************************************************************************************************
ok: [deb01] => (item=/tmp/tomcat-ansible/roles/tomcat/vars/Debian.yml)
TASK [tomcat : include_tasks] **************************************************************************************************************************
included: /tmp/tomcat-ansible/roles/tomcat/tasks/tomcat-setup-Debian.yml for deb01
TASK [tomcat : Ensure the system can use the HTTPS transport for APT.] *********************************************************************************
ok: [deb01]
TASK [tomcat : Install APT HTTPS transport.] ***********************************************************************************************************
skipping: [deb01]
TASK [tomcat : Install basic packages] *****************************************************************************************************************
[WARNING]: Updating cache and auto-installing missing dependency: python-apt
changed: [deb01]
TASK [tomcat : Install Default Java (Debian/Ubuntu)] ***************************************************************************************************
changed: [deb01]
TASK [tomcat : Add tomcat group] ***********************************************************************************************************************
changed: [deb01]
TASK [tomcat : Add "tomcat" user] **********************************************************************************************************************
changed: [deb01]
TASK [tomcat : Download Tomcat] ************************************************************************************************************************
changed: [deb01]
TASK [tomcat : Create a tomcat directory] **************************************************************************************************************
changed: [deb01]
TASK [tomcat : Extract tomcat archive] *****************************************************************************************************************
changed: [deb01]
TASK [tomcat : Copy tomcat service file] ***************************************************************************************************************
changed: [deb01]
TASK [tomcat : Start and enable tomcat] ****************************************************************************************************************
changed: [deb01]
PLAY RECAP *********************************************************************************************************************************************
deb01 : ok=13 changed=9 unreachable=0 failed=0 skipped=1 rescued=0 ignored=0
Step 4: Test your Tomcat installation on Debian
Access server URL on port 8080. Test the installation and configuration of tomcat.
- Tomcat Web Application Manager Dashboard:
http://
:8080/manager/html - Tomcat Virtual Host Manager Dashboard:
http://
:8080/host-manager/html
You can also access the web application manager and host manager by clicking the UI button:
Authentication is required to access both sections.
Server status page:
Web Application Manager page:
Web hosting manager page:
You should now be able to deploy your application to a Tomcat server running on a Debian 10 Linux machine.