Skip to main content
AI
  • Get started with AI

    • Red Hat AI

      Accelerate the development and deployment of enterprise AI solutions.

    • AI learning hub

      Explore learning materials and tools, organized by task.

    • AI interactive demos

      Click through scenarios with Red Hat AI, including training LLMs and more.

    • AI/ML learning paths

      Expand your Red Hat OpenShift AI knowledge using these learning resources.

    • AI quickstarts

      Focused AI use cases designed for fast deployment on Red Hat AI platforms.

    • No-cost AI training

      Foundational Red Hat AI training.

  • Featured resources

    • Red Hat OpenShift AI
    • Open source AI for developers
    • AI product application development
    • Open source-powered AI/ML for hybrid cloud
    • AI and Node.js cheat sheet

Red Hat AI Factory with NVIDIA

Red Hat AI Factory with NVIDIA is a co-engineered, enterprise-grade AI solution for building, deploying, and managing AI at scale across hybrid cloud environments.

Learn
  • Self-guided

    • Documentation

      Find answers, get step-by-step guidance, and learn how to use Red Hat products.

    • Learning paths

      Explore curated walkthroughs for common development tasks.

    • Guided learning

      Receive custom learning paths powered by our AI assistant.

    • See all learning
  • Hands-on

    • Developer Sandbox

      Spin up Red Hat's products and technologies without setup or configuration.

    • Interactive labs

      Learn by doing in these hands-on, browser-based experiences.

    • Interactive demos

      Click through product features in these guided tours.

  • Browse by topic

    • AI/ML
    • Automation
    • Java
    • Kubernetes
    • Linux
    • See all topics
  • Training & certifications

    • Courses and exams
    • Certifications
    • Skills assessments
    • Red Hat Academy
    • Learning subscription
    • Explore training
Build
  • Get started

    • Red Hat build of Podman Desktop

      A downloadable, local development hub to experiment with our products and builds.

    • Developer Sandbox

      Spin up Red Hat's products and technologies without setup or configuration.

  • Download products

    • Red Hat Enterprise Linux
    • Red Hat AI
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform
    • See all products
  • Featured

    • Red Hat build of OpenJDK
    • Red Hat JBoss Enterprise Application Platform
    • Red Hat OpenShift Dev Spaces
    • Red Hat Developer Toolset
  • References

    • E-books
    • Documentation
    • Cheat sheets
    • Architecture center
Community
  • Get involved

    • Events
    • Live AI events
    • Red Hat Summit
    • Red Hat Accelerators
    • Community discussions
  • Follow along

    • Articles & blogs
    • Developer newsletter
    • Videos
    • Github
  • Get help

    • Customer service
    • Customer support
    • Regional contacts
    • Find a partner

Join the Red Hat Developer program

Download Red Hat products and project builds, access support documentation, learning content, and more.

ConsoleDocsSupport Search
New For you

Recommended

We'll recommend resources you may like as you browse. Try these suggestions for now.

  • Product downloads
  • Cheat sheets
  • Red Hat Developer learning portal
  • Developer blog
  • E-books
  • Developer Sandbox
Log in

Get more with a Red Hat Developer account

  • Product downloads
  • Console access
  • Event registration
  • Training & trials
Explore more account benefitsLog in or register

A subscription may be required for some services.

Contact us

Automate Red Hat JBoss Web Server deployments with Ansible

August 30, 2021
Romain Pelisse
Related topics:
AutomationDevOpsJavaLinux
Related products:
Red Hat Ansible Automation PlatformRed Hat JBoss Web ServerRed Hat Enterprise Linux

    Red Hat JBoss Web Server combines a web server (Apache HTTPD), a servlet engine (Apache Tomcat), and modules for load balancing (mod_jk and mod_cluster). Ansible is one of the best automation tools on the market. In this article, we'll use Ansible to completely automate the deployment of a JBoss Web Server instance on a freshly installed Red Hat Enterprise Linux (RHEL) server.

    Our objective is to automate a JBoss Web Server deployment through the following tasks:

    • Retrieve the archive containing JBoss Web Server from a repository and install the files it contains on the system.
    • Configure the Red Hat Enterprise Linux operating system (create users, groups, and the required setup files to make JBoss Web Server a systemd service).
    • Fine-tune the configuration of the JBoss Web Server server itself (bind it to the appropriate interface and port).
    • Deploy a web application and starting the systemd service.
    • Perform a health check if the deployed application is accessible.

    Ansible fully automates these operations, with no manual steps required.

    Set the target environment

    Before we start the automation, we need to specify our target environment. In this case, we're using RHEL 8 with Python 3.6.

    # cat /etc/redhat-release
    
    Red Hat Enterprise Linux release 8.4 (Ootpa)
    
    # ansible --version
    
    ansible 2.9.22
    
      config file = /etc/ansible/ansible.cfg
    
      configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
    
      ansible python module location = /usr/lib/python3.6/site-packages/ansible
    
      executable location = /usr/bin/ansible
    
      python version = 3.6.8 (default, Mar 18 2021, 08:58:41) [GCC 8.4.1 20200928 (Red Hat 8.4.1-1)]

    Note: The playbook might not work if you want to use a different Python version or target operating system.

    Install the JBoss Web Server Ansible collection

    Once you have RHEL 8 set up and Ansible ready to go, you need to install the JBoss Web Server Ansible collection. Ansible uses the collection to perform the following tasks on JBoss Web Server:

    • Ensure required dependencies are installed (e.g., unzip).
    • Install Java (if missing and requested).
    • Install the binaries and integrate the software into the system (user, group, etc.).
    • Deploy the configuration files.
    • Start and enable JBoss Web Server as a systemd service.
    • Configure a Password Vault with JBoss Web Server and a load balancer (e.g., mod_cluster)—not used for this article.

    Here's the installation:

    $ ansible-galaxy collection install middleware_automation.jws
    
    Process install dependency map
    
    Starting collection install process
    
    Installing 'middleware_automation.jws:0.0.1' to '/root/.ansible/collections/ansible_collections/middleware_automation/jws'
    
    Installing 'middleware_automation.redhat_csp_download:1.1.2' to '/root/.ansible/collections/ansible_collections/middleware_automation/redhat_csp_download'

    Note: Ansible Galaxy fetches and downloads the collection's dependencies. That is why, at the end of the execution, the JBoss Web Server collection was installed, as well as redhat_csp_download, which will help facilitate the retrieval of the archive containing the JBoss Web Server server.

    Installing the collection reduces the configuration to achieve our automation to the bare minimum.

    Create a playbook to test the installation

    Before we continue, let's create a minimal playbook to confirm that the collection was properly installed:

    ---
    
    - name: "JBoss Web Server installation and configuration"
    
      hosts: "all"
    
      become: yes
    
      collections:
    
    – middleware_automation.jws
    
      tasks :

    In its current state, this playbook doesn’t perform any tasks on the target system. If the playbook runs successfully, then we know that the collection has been properly installed.

    # ansible-playbook -i hosts min.yml
    
    
    
    PLAY [JBoss Web Server installation and configuration] *************************************************************************
    
    
    
    TASK [Gathering Facts] *****************************************************************************************************************
    
    ok: [localhost]
    
    
    
    PLAY RECAP *****************************************************************************************************************************
    
    localhost              : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0

    Install the Apache Tomcat web server

    Next, we'll install the Apache Tomcat web server, which consists of several steps.

    Download the archive

    First, let's modify our minimal playbook to retrieve the archive containing Apache Tomcat. For this purpose, we will leverage the get_url module from Ansible:

    ---
    
    - name: "JBoss Web Server installation and configuration"
    
      hosts: "all"
    
      become: yes
    
      vars:
    
    tomcat_version: 9.0.50
    
    tomcat_download_url: https://archive.apache.org/dist/tomcat/tomcat-9/v{{tomcat_version}}/bin/apache-tomcat-{{tomcat_version}}.zip
    
    tomcat_install_dir: /opt
    
    tomcat_zipfile: “{{tomcat_install_dir}}/tomcat.zip"
    
      collections:
    
    - middleware_automation.jws
    
    pre_tasks:
    
    - name: "Download latest JBoss Web Server Zipfile from {{ tomcat_download_url }}."
    
       get_url:
    
         url: "{{ tomcat_download_url }}"
    
         dest: "{{ tomcat_zipfile }}"
    
                remote_src: yes
    
       when:
    
         - tomcat_download_url is defined

    Note: The playbook downloads the archive during the pre_tasks section. It’s important to use the role provided by the JBoss Web Server collection in the next step. This role will be executed before the tasks block and after the pre_tasks block, and it requires that the archive file be already present on the target system.

    Execute a new playbook:

    # ansible-playbook -i hosts playbook.yml
    
    
    
    PLAY [JBoss Web Server installation and configuration] *************************************************************************
    
    
    
    TASK [Gathering Facts] *****************************************************************************************************************
    
    ok: [localhost]
    
    
    
    TASK [Download latest JBoss Web Server Zipfile from https://archive.apache.org/dist/tomcat/tomcat-9/v9.0.50/bin/apache-tomcat-9.0.50.zip.] ***
    
    changed: [localhost]
    
    
    
    PLAY RECAP *****************************************************************************************************************************
    
    localhost              : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0

    Install Java

    JBoss Web Server is a Java-based server, so the target system is required to install a Java Virtual Machine (JVM). While Ansible primitives can perform such tasks natively, the jws role can also take care of this part, provided the tomcat_java_version variable is defined:

    - name: "JBoss Web Server installation and configuration"
    
      hosts: "all"
    
      become: yes
    
      vars:
    
    ...
    
    tomcat_java_version: 1.8.0
    
      collections:
    
    – middleware_automation.jws
    
    …

    Keep in mind that this feature has limits; it works only if the target system’s distribution belongs to the Red Hat family:

    $ ansible -m setup localhost | grep family
    
         "ansible_os_family": "RedHat",

    Install Java web server

    For Java web server to work, we need to provide one more variable to our playbook. The tomcat_setup (set to true) signals to the jws role that we want it to perform the installation:

    ---
    
    - name: "JBoss Web Server installation and configuration"
    
      hosts: "all"
    
      become: yes
    
      vars:
    
    tomcat_setup: true
    
    ...
    
      collections:
    
    - middleware_automation.jws
    
      roles:
    
    - jws
    
      pre_tasks:
    
    ...
    
      tasks:

    Run the playbook again

    Let’s run our playbook again to see if it works as expected.

    As you can see, quite a lot happened during this execution. Indeed, the jws role took care of all the setup:

    1. Deploying a base configuration.
    2. Removing unused applications.
    3. Starting the web server.

    The playbooks also perform a few tasks on the target system, like installing any required dependencies if they are missing and ensuring the environment is properly configured.

    Configure JBoss Web Server as a systemd service

    A nice feature of the jws role is the included functionality to configure JBoss Web Server as a systemd service. For this to occur, you just need to define the tomcat_service_name variable:

    ---
    
    - name: "JBoss Web Server installation and configuration"
    
      hosts: "all"
    
      become: yes
    
      vars:
    
    …
    
    tomcat_service_name: tomcat
    
    ...
    
      collections:
    
    - middleware_automation.jws
    
      roles:
    
         …

    Keep in mind this only works when systemd is installed and the system belongs to the Red Hat family.

    # systemctl status tomcat
    
    ● tomcat.service - JBoss Web Server Web Application Container
    
      Loaded: loaded (/usr/lib/systemd/system/tomcat.service; enabled; vendor preset: disabled)
    
      Active: active (running) since Thu 2021-07-22 16:52:08 UTC; 16h ago
    
       Main PID: 6234 (java)
    
       Tasks: 37 (limit: 307)
    
      Memory: 187.4M
    
         CPU: 21.528s
    
      CGroup: /system.slice/tomcat.service
    
    └─6234 /usr/bin/java -Djava.util.logging.config.file=/opt/apache-tomcat-9.0.50/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djdk.tls.ephemeralDHKeySize=2048 -Djava.protocol.handler.pkgs=org.apache.catalina.webresources -Dorg.apache.catalina.security.SecurityListener.UMASK=0027 -Dignore.endorsed.dirs= -classpath /opt/apache-tomcat-9.0.50/bin/bootstrap.jar:/opt/apache-tomcat-9.0.50/bin/tomcat-juli.jar -Dcatalina.base=/opt/apache-tomcat-9.0.50 -Dcatalina.home=/opt/apache-tomcat-9.0.50 -Djava.io.tmpdir=/opt/apache-tomcat-9.0.50/temp org.apache.catalina.startup.Bootstrap start
    
    
    
    Jul 22 16:52:08 4414af93c931 systemd[1]: Started Apache Tomcat Web Application Container.
    
    Jul 22 16:52:08 4414af93c931 systemd-service.sh[6220]: Tomcat started.
    
    Jul 22 16:52:08 4414af93c931 systemd-service.sh[6219]: Tomcat runs with PID: 6234

    Deploy a web application

    Now that JBoss Web Server is running, let’s modify the playbook and facilitate the deployment of a web application:

    tasks:
    
        - name: " Checks that server is running"
    
          uri:
    
            url: "http://localhost:8080/"
    
            status_code: 404
    
            return_content: no
    
    
    
        - name: "Deploy demo webapp"
    
          get_url:
    
            url: 'https://people.redhat.com/~rpelisse/info-1.0.war'
    
            dest: "{{ tomcat_home }}/webapps/info.war"
    
          notify:
    
            - Restart Tomcat service

    A handler in the jws role restarts JBoss Web Server when the web application is downloaded. To finish our demonstration, we can add a quick test in the post_tasks section of the playbook to confirm that the web application is functional:

      post_tasks:
    
    - name: "Sleep for {{ tomcat_sleep }} seconds to let Tomcat starts "
    
       wait_for:
    
         timeout: "{{ tomcat_sleep }}"
    
    
    
    - name: "Test application"
    
       get_url:
    
         url: "http://localhost:8080/info/"
    
         dest: /tmp/info.txt

    Conclusion

    That’s all for today! Future articles will demonstrate other features provided by the Red Hat JBoss Web Server collection, including support for mod_cluster and securing the server with Tomcat’s Vault feature.

    In the meantime, you can find the playbook used for this article in the Ansible Collection for JBoss Web Server GitHub repository.

    Last updated: September 19, 2023

    Related Posts

    • The wait is over: JBoss Web Server 5 with Tomcat 9 is here!

    • Install Apache Tomcat and deploy a Java web application on Red Hat OpenShift

    • Automate workshop setup with Ansible playbooks and CodeReady Workspaces

    • WildFly server configuration with Ansible collection for JCliff, Part 1

    Recent Posts

    • A day in the life of an NVIDIA H100 on Red Hat OpenShift 5

    • Migrate BuildConfigs to builds for Red Hat OpenShift with one plug-in install

    • Run Red Hat Enterprise Linux CoreOS on NVIDIA BlueField DPUs

    • Agent harness engineering: Separating model capabilities from enforcement

    • What's new for developers in Red Hat Enterprise Linux 10.3 and 9.9

    Red Hat Developers logo

    Platforms

    • Red Hat AI
    • Red Hat Enterprise Linux
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform
    • See all products

    Build

    • Developer Sandbox
    • Developer tools
    • Interactive tutorials
    • API catalog

    Quicklinks

    • Learning resources
    • E-books
    • Cheat sheets
    • Blog
    • Events
    • Newsletter

    Communicate

    • About us
    • Contact sales
    • Find a partner
    • Report a website issue
    • Site status dashboard
    • Report a security problem

    Red Hat Developer

    Build here. Go anywhere.

    We serve the builders. The problem solvers who create careers with code.

    Join us if you’re a developer, software engineer, web designer, front-end designer, UX designer, computer scientist, architect, tester, product manager, project manager or team lead.

    Sign me up

    Red Hat legal and privacy links

    • About Red Hat
    • Jobs
    • Events
    • Locations
    • Contact Red Hat
    • Red Hat Blog
    • Inclusion at Red Hat
    • Cool Stuff Store
    • Red Hat Summit
    © 2026 Red Hat

    Red Hat legal and privacy links

    • Privacy statement
    • Terms of use
    • All policies and guidelines
    • Digital accessibility
    Ask AI