You can support us by downloading this article as PDF from the Link below. Download the guide as PDF

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 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.

Ansible role to setup tomcat

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-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 trusty main" | sudo tee /etc/apt/sources.list.d/ansible.list
sudo apt-key adv --keyserver --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.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 Ansible role from Github

The tomcat ansible role is available publicly on Github for use. Clone it to your workstation.

cd /tmp/
git clone
cd tomcat-ansible
  • Update your inventory, e.g:
$ vim hosts
[tomcat-nodes] # 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
    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
    - 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 install debian
  • 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:

tomcat install debian access ui

Authentication is required when accessing both sections.

Server Status page:

tomcat install debian 02

Web application manager page:

tomcat install debian 03

Virtual Host manager page:

tomcat install debian 04

You should now be able to deploy applications to your Tomcat server running on Debian 10 Linux machine.

You can support us by downloading this article as PDF from the Link below. Download the guide as PDF