Apache Tomcat is a free and open-source HTTP server designed to serve Java web pages. Tomcat is an implementation of the Java Servlet, JavaServer Pages, Java Expression Language, and Java WebSocket technologies. It is widely deployed and powers various mission-critical web applications around the world. This tutorial will discuss how you can easily install Tomcat on Debian 11 / Debian 10 Linux with Ansible.
The standard way of installing Tomcat on a Linux system such as Debian is manual and time-consuming. I wrote an Ansible role to simplify the process. The link to the Github project is shared below.
I’ll cover the steps you’ll use to install Tomcat with this ansible role in your Debian 10 system.
Step 1: Install Ansible
The main dependency on your Workstation is Ansible. Install Ansible on your Linux system using the commands shared below.
###### CentOS ###### sudo yum -y install epel-release && sudo yum -y install ansible ###### Fedora ###### sudo dnf -y install ansible ###### Ubuntu / Linux Mint ###### sudo apt install -y software-properties-common sudo apt-add-repository --yes --update ppa:ansible/ansible sudo apt update sudo apt 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 ansible installation:
$ ansible --version ansible 2.9.27 config file = /etc/ansible/ansible.cfg configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules'] ansible python module location = /usr/lib/python2.7/site-packages/ansible executable location = /usr/bin/ansible python version = 2.7.18 (default, Aug 27 2020, 21:22:52) [GCC 7.3.1 20180712 (Red Hat 7.3.1-9)]
Step 2: Clone Ansible role from Github
The tomcat ansible role is available publicly on Github for use. Clone it to your workstation.
cd /tmp/
git clone https://github.com/jmutai/tomcat-ansible.git
cd tomcat-ansible
- Update your inventory, e.g:
$ vim hosts
[tomcat_nodes]
192.168.20.55 # Add Server IP address, one line per server
- Update variables in playbook 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.64 # Tomcat version to install
ui_manager_user: manager # User who can access the UI manager section only
ui_manager_pass: Str0ngManagerPassw3rd # UI manager user password
ui_admin_username: admin # User who can access bpth manager and admin UI sections
ui_admin_pass: Str0ngAdminPassw3rd # UI admin password
roles:
- tomcat
When using non root remote user, become_method is necessary.
become: yes
become_method: sudo
Step 3: Install Apache Tomcat 9 on Debian 10 With Ansible
Once all values are updated, you can then run the playbook against your nodes.
Playbook executed as root user – with ssh key:
$ ansible-playbook -i hosts tomcat-setup.yml
Playbook executed as root user – with password:
$ ansible-playbook -i hosts tomcat-setup.yml --ask-pass
Playbook executed as sudo user – with password:
$ ansible-playbook -i hosts tomcat-setup.yml --ask-pass --ask-become-pass
Playbook executed as sudo user – with ssh key and sudo password:
$ ansible-playbook -i hosts tomcat-setup.yml --ask-become-pass
Playbook executed as sudo user – with ssh key and passwordless sudo:
$ ansible-playbook -i hosts tomcat-setup.yml --ask-become-pass
A successful installation output will show output similar to below.
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 Tomcat Installation on Debian
Visit the server URL on port 8080. to test tomcat installation and configuration.
- Tomcat web application manager dashboard:
http://<domain_or_IP_address>:8080/manager/html
- Tomcat virtual host manager dashboard:
http://<domain_or_IP_address>:8080/host-manager/html
You can also access the web application manager and host manager by clicking the UI buttons:
Authentication is required when accessing both sections.
Server Status page:
Web application manager page:
Virtual Host manager page:
You should now be able to deploy applications to your Tomcat server running on Debian 10 Linux machine.