Installing Tomcat server on Ubuntu 22.04 with Ansible

Introduction

Apache tomcat is servlet container which is use the deploy JAVA project, The Jakarta Servlet, Jakarta Expression Language, and WebSocket technologies are all implemented by Apache Tomcat, a free and open-source application. It provides an HTTP web server environment that is “pure Java” and allows Java code to run. As a result, it is not a full JEE application server but rather a Java web application server.

Ansible is a collection of software tools that let infrastructure be written in code. Software provisioning, configuration management, and application deployment are all included in the open-source suite.

Prerequisites

  • Up and running Ansible server.
  • Root access of target machine.
  • Internet connectivity with nodes.

We’ll show you how to use the Ansible automation tool to install the Apache Tomcat Server on a Ubuntu machine in this post.

Step 1: Creating Tomcat Playbook

We need to create a tomcat-playbook.ymlAnsible play is very import to to execute the task one by one.

To create a tomcat-playbook.yml

nano tomcat-playbook.yml

Paste the following code.

- name: Install Tomcat
  hosts: tomcatservers
  become: true
  vars:
    - TOMCAT9_URL : "https://dlcdn.apache.org/tomcat/tomcat-9/v9.0.71/bin/apache-tomcat-9.0.71.tar.gz"
  
  tasks:
  - name: Update apt-get repo and cache
    apt: update_cache=yes force_apt_get=yes cache_valid_time=3600 

  - name: Install Java
    apt:
      name: openjdk-11-jdk
      state: present
  
  - name: Download Tomcat
    get_url:
      url: "{{ TOMCAT9_URL }}"
      dest: /tmp/
      validate_certs: no

  - name: Creating Apache Tomcat home directory.
    command: mkdir /opt/tomcat    
      
  - name: Extract Tomcat
    shell: tar -xzvf /tmp/apache-tomcat-*tar.gz -C /opt/tomcat --strip-components=1
  

  - name: Start Tomcat
    shell: /opt/tomcat/bin/startup.sh
    ignore_errors: true
  
  - name: Wait for Tomcat to start
    wait_for:
      host: localhost
      port: 8080
      state: started

Save and exit from the text editor, This playbook does the following:

  • Installs Java on the remote server.
  • Downloads and extracts Apache Tomcat to the /opt directory.
  • Renames the directory to /opt/tomcat.
  • Starts Tomcat using the startup script.
  • Waits for Tomcat to start on port 8080.

Note that this is just one example, and the specific details of your playbook will depend on your use case and the specific version of Tomcat you’re using.

Step 2: Execute tomcat Playbook

We are good to execute the tomcat-playbook.yml by following the given command.

ansible-playbook tomcat-playbook.yml

The above command start the installation of tomcat server on target machine.

Step 3: Testing Apache Tomcat 9 

By default tomcat will up and running on port 8080 So we need to open the browser with given address.

http://localhost:8080 

http://IP-ADDRESS:8080

You should get Apache tomcat web page like this.

Conclusion

We have successfully installed tomcat server on Ubuntu 22.04 LTS with ansible. If you still have any questions, please leave a comment below: 

Author

Installing Tomcat server on Ubuntu 22.04 with Ansible

10 thoughts on “Installing Tomcat server on Ubuntu 22.04 with Ansible

  1. Good web site! I truly love how it is easy on my eyes and the data are well written. I am wondering how I could be notified whenever a new post has been made. I’ve subscribed to your RSS which must do the trick! Have a nice day!

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top