Skip to main content
Redhat Developers  Logo
  • Products

    Featured

    • Red Hat Enterprise Linux
      Red Hat Enterprise Linux Icon
    • Red Hat OpenShift AI
      Red Hat OpenShift AI
    • Red Hat Enterprise Linux AI
      Linux icon inside of a brain
    • Image mode for Red Hat Enterprise Linux
      RHEL image mode
    • Red Hat OpenShift
      Openshift icon
    • Red Hat Ansible Automation Platform
      Ansible icon
    • Red Hat Developer Hub
      Developer Hub
    • View All Red Hat Products
    • Linux

      • Red Hat Enterprise Linux
      • Image mode for Red Hat Enterprise Linux
      • Red Hat Universal Base Images (UBI)
    • Java runtimes & frameworks

      • JBoss Enterprise Application Platform
      • Red Hat build of OpenJDK
    • Kubernetes

      • Red Hat OpenShift
      • Microsoft Azure Red Hat OpenShift
      • Red Hat OpenShift Virtualization
      • Red Hat OpenShift Lightspeed
    • Integration & App Connectivity

      • Red Hat Build of Apache Camel
      • Red Hat Service Interconnect
      • Red Hat Connectivity Link
    • AI/ML

      • Red Hat OpenShift AI
      • Red Hat Enterprise Linux AI
    • Automation

      • Red Hat Ansible Automation Platform
      • Red Hat Ansible Lightspeed
    • Developer tools

      • Red Hat Trusted Software Supply Chain
      • Podman Desktop
      • Red Hat OpenShift Dev Spaces
    • Developer Sandbox

      Developer Sandbox
      Try Red Hat products and technologies without setup or configuration fees for 30 days with this shared Openshift and Kubernetes cluster.
    • Try at no cost
  • Technologies

    Featured

    • AI/ML
      AI/ML Icon
    • Linux
      Linux Icon
    • Kubernetes
      Cloud icon
    • Automation
      Automation Icon showing arrows moving in a circle around a gear
    • View All Technologies
    • Programming Languages & Frameworks

      • Java
      • Python
      • JavaScript
    • System Design & Architecture

      • Red Hat architecture and design patterns
      • Microservices
      • Event-Driven Architecture
      • Databases
    • Developer Productivity

      • Developer productivity
      • Developer Tools
      • GitOps
    • Secure Development & Architectures

      • Security
      • Secure coding
    • Platform Engineering

      • DevOps
      • DevSecOps
      • Ansible automation for applications and services
    • Automated Data Processing

      • AI/ML
      • Data Science
      • Apache Kafka on Kubernetes
      • View All Technologies
    • Start exploring in the Developer Sandbox for free

      sandbox graphic
      Try Red Hat's products and technologies without setup or configuration.
    • Try at no cost
  • Learn

    Featured

    • Kubernetes & Cloud Native
      Openshift icon
    • Linux
      Rhel icon
    • Automation
      Ansible cloud icon
    • Java
      Java icon
    • AI/ML
      AI/ML Icon
    • View All Learning Resources

    E-Books

    • GitOps Cookbook
    • Podman in Action
    • Kubernetes Operators
    • The Path to GitOps
    • View All E-books

    Cheat Sheets

    • Linux Commands
    • Bash Commands
    • Git
    • systemd Commands
    • View All Cheat Sheets

    Documentation

    • API Catalog
    • Product Documentation
    • Legacy Documentation
    • Red Hat Learning

      Learning image
      Boost your technical skills to expert-level with the help of interactive lessons offered by various Red Hat Learning programs.
    • Explore Red Hat Learning
  • Developer Sandbox

    Developer Sandbox

    • Access Red Hat’s products and technologies without setup or configuration, and start developing quicker than ever before with our new, no-cost sandbox environments.
    • Explore Developer Sandbox

    Featured Developer Sandbox activities

    • Get started with your Developer Sandbox
    • OpenShift virtualization and application modernization using the Developer Sandbox
    • Explore all Developer Sandbox activities

    Ready to start developing apps?

    • Try at no cost
  • Blog
  • Events
  • Videos

WildFly server configuration with Ansible collection for JCliff, Part 2

December 3, 2020
Romain Pelisse
Related topics:
JavaDevOpsLinux

Share:

    Welcome to the second part of this series introducing Ansible collection for JCliff. This new extension is designed for fine-tuning WildFly or Red Hat JBoss Enterprise Application Platform (JBoss EAP) configurations using Ansible. In Part 1, we installed JCliff and its Ansible collection and prepared our environment. We set up a minimal, working playbook for installing JCliff on the target system. In this article, we will focus on configuring a few of our WildFly server’s subsystems.

    Configuring a new data source

    Java applications often need to consume data originating from a database. To connect to a database, WildFly uses a driver. Multiple applications hosted on WildFly can even access a data source at the same time. In this section, you will learn how to configure the data source subsystem using Ansible.

    WildFly includes an embedded in-memory database called H2. In the H2 database, the required Java Database Connectivity (JDBC) driver is available and ready to use. The following data source configuration example is already defined in the server’s configuration:

    <subsystem xmlns="urn:jboss:domain:datasources:6.0">
                <datasources>
                    <datasource jndi-name="java:jboss/datasources/ExampleDS" pool-name="ExampleDS" enabled="true" use-java-context="true" statistics-enabled="${wildfly.datasources.statistics-enabled:${wildfly.statistics-enabled:false}}">
                        <connection-url>jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE</connection-url>
                        <driver>h2</driver>
                        <security>
                            <user-name>sa</user-name>
                            <password>sa</password>
                        </security>
                    </datasource>
    ...

    Now, let's say we need another H2 database instance for testing purposes. To set up this new instance we'll use the datasources: element in the jcliff: module:

    ---
    
    - hosts: localhost
      gather_facts: true
      vars:
        jboss_home: "{{ lookup('env','JBOSS_HOME') }}"
      collections:
        - wildfly.jcliff
      roles:
        - jcliff
      tasks:
        - jcliff:
            wfly_home: "{{ jboss_home }}"
            subsystems:
              - system_props:
                  - name: jcliff.enabled
                    value: 'enabled.plus'
              - datasources:
                  - name: H2DS4Test
                    use_java_context: 'true'
                    jndi_name: java:jboss/datasources/H2DS4Test
                    connection_url: "jdbc:h2:mem:test2;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE"
                    driver_name: h2
    

    Here again, the configuration is straightforward. We only had to add the required connection information. When we run the playbook, a new data source is added. We can verify this by checking WildFly's log file:

    ...
    09:53:03,542 INFO  [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-6) WFLYJCA0001: Bound data source [java:jboss/datasources/H2DS4Test]
    ...

    Setting up a new JDBC driver

    Now, we can go further by using Ansible to add a new JDBC driver to WildFly. First, we’ll need to download the driver and deploy it inside a JBoss module. We set up the deployment by creating the required directory structure under the ${JBOSS_HOME}/modules directory and adding the XML descriptor to it. The example below shows how to use Ansible to add the JDBC driver to WildFly.

    ...
    
    vars:
      jboss_home: "{{ lookup('env','JBOSS_HOME') }}"
      psql_module_home: "{{ jboss_home }}//modules/org/postgresql/main/"
      jdbc_driver_version: 9.2-1002-jdbc4
      jdbc_driver_jar_filename: "postgresql-{{ jdbc_driver_version }}.jar"
    collections:
      - wildfly.jcliff
    roles:
      - jcliff
    
    tasks:
    
      - name: "Set up module dir for Postgres JDBC Driver"
        file:
          path: "{{ psql_module_home }}"
          state: directory
          recurse: yes
    
      - name: "Ensures WildFly Postgres Driver is present"
        uri:
          url: "https://repo.maven.apache.org/maven2/org/postgresql/postgresql/{{ jdbc_driver_version }}/{{ jdbc_driver_jar_filename }}"
          dest: "{{ psql_module_home }}"
          creates: "{{ psql_module_home }}"
    
      - name: "Deploy module.xml for Postgres JDBC Driver"
        template:
          src: templates/pgsql_jdbc_driver_module.xml.j2
          dest: "{{ psql_module_home }}/module.xml"
    

    With three tasks, we have managed to fully automate the installation of a new JDBC driver for WildFly. We still need to update the server’s configuration to make the new driver available to our hosted applications. We’ll do that in a moment. First, let's run this part of the playbook to ensure everything is working as expected:

    $ ansible-playbook playbook.yml
    ...
    TASK [wildfly.jcliff.jcliff : Test if package jcliff is already installed] *******************************************************************************************************************
    ok: [localhost]
    
    TASK [wildfly.jcliff.jcliff : Install Jcliff using standalone binary] ************************************************************************************************************************
    skipping: [localhost]
    
    TASK [Set up module dir for Postgres JDBC Driver] ********************************************************************************************************************************************
    changed: [localhost]
    
    TASK [Ensures WildFly Postgres Driver is present] ********************************************************************************************************************************************
    ok: [localhost]
    
    TASK [Deploy module.xml for Postgres JDBC Driver] ********************************************************************************************************************************************
    changed: [localhost]
    
    TASK [jcliff] ********************************************************************************************************************************************************************************
    ok: [localhost]
    
    PLAY RECAP ***********************************************************************************************************************************************************************************
    localhost                  : ok=10   changed=2    unreachable=0    failed=0    skipped=2    rescued=0    ignored=0
    

    Everything we did to install our driver used Ansible's existing primitives. The new part comes now. Thanks to JCliff, we can activate the driver within the server:

       - jcliff:
           wfly_home: "{{ jboss_home }}"
           subsystems:
             - system_props:
                 - name: jcliff.enabled
                   value: 'enabled.plus'
             - drivers:
                 - driver_name: postgresql
                   driver_module_name: org.postgresql
                   driver_class_name: org.postgresql.Driver
                   driver_xa_datasource_class_name: org.postgresql.xa.PGXADataSource  
             - datasources:
                 - name: H2DS4Test
                   use_java_context: 'true'
                   jndi_name: java:jboss/datasources/H2DS4Test
                   connection_url: "jdbc:h2:mem:test2;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE"
                   driver_name: h2
    

    After running the playbook, we can see that WildFly has properly deployed the driver. Checking the server's log file verifies it:

    ...
    13:24:25,474 INFO  [org.jboss.as.connector.subsystems.datasources] (management-handler-thread - 1) WFLYJCA0005: Deploying non-JDBC-compliant driver class org.postgresql.Driver (version 9.2)
    13:24:25,474 INFO  [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-1) WFLYJCA0018: Started Driver service with driver-name = postgresql
    13:24:27,464 INFO  [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-2) WFLYJCA0019: Stopped Driver service with driver-name = postgresql
    ...

    Deploying an application with JCliff

    Until now, we have used JCliff only to update WildFly’s configuration. But it can go even further: We can also use JCliff to deploy applications on WildFly. In this section, we will deploy Jenkins CI (webapp) on our WildFly server.

    First, we need to add a yum repository so that we can install the required files on the target’s system. Add the following to the Ansible playbook before the call to the jcliff: module:

    ...
       - name: Jenkins Yum Repository
         yum_repository:
             name: jenkins
             description: Jenkins
             baseurl: http://pkg.jenkins.io/redhat
             gpgcheck: 1
    
       - name: Install Jenkins
         yum:
             name: jenkins
             state: present
    ...

    Note: This Yum repository requires you to import a Gnu Privacy Guard (GPG) key, so be sure to do that before running the playbook. Enter the following to import the key:
    rpm --import https://pkg.jenkins.io/redhat/jenkins.io.key
    .

    When the playbook runs successfully, the RPM package associated with Jenkins will be installed. The WAR file that we use to deploy the application will be available on the target’s system:

    $ yum whatprovides */jenkins*.war
    … 
    
    jenkins-2.253-1.1.noarch : Jenkins Automation Server
    Repo        : @jenkins
    Matched from:
    Filename    : /usr/lib/jenkins/jenkins.war
    

    Now, we just need to deploy the application on the WildFly server. To do that, we’ll update the jcliff: module configuration to add the deployments: element:

       - jcliff:
           wfly_home: "{{ jboss_home }}"
           subsystems:
             - system_props:
                 - name: jcliff.enabled
                   value: 'enabled.plus'
             - drivers:
                 - driver_name: postgresql
                   driver_module_name: org.postgresql
                   driver_class_name: org.postgresql.Driver
                   driver_xa_datasource_class_name: org.postgresql.xa.PGXADataSource  
             - datasources:
                 - name: H2DS4Test
                   use_java_context: 'true'
                   jndi_name: java:jboss/datasources/H2DS4Test
                   connection_url: "jdbc:h2:mem:test2;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE"
                   driver_name: h2
             - deployments:  
                 - name: jenkins
                   path: /usr/lib/jenkins/jenkins.war
    

    Once again, we only need to add the path to the WAR file and the name of the application to be deployed. Ansible and JCliff handle the rest.

    The playbook runs successfully, and it’s easy to verify that Jenkins has been deployed. Here, again, checking the server’s logfile confirms it:

    ...
    14:06:09,148 INFO  [org.jboss.as.repository] (management-handler-thread - 2) WFLYDR0001: Content added at location /opt/wildfly-20.0.1.Final/standalone/data/content/6b/30899e9a28a361241d19561c965977aea70d7f/content
    14:06:09,171 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-5) WFLYSRV0027: Starting deployment of "jenkins" (runtime-name: "jenkins")
    14:06:09,840 WARN  [org.jboss.as.server.deployment] (MSC service thread 1-5) WFLYSRV0274: Excluded dependency com.fasterxml.jackson.core.jackson-core via jboss-deployment-structure.xml does not exist.
    14:06:09,841 WARN  [org.jboss.as.server.deployment] (MSC service thread 1-5) WFLYSRV0274: Excluded dependency org.jboss.resteasy.resteasy-jackson-provider via jboss-deployment-structure.xml does not exist.
    14:06:09,841 WARN  [org.jboss.as.server.deployment] (MSC service thread 1-5) WFLYSRV0274: Excluded dependency com.fasterxml.jackson.core.jackson-databind via jboss-deployment-structure.xml does not exist.
    14:06:09,841 WARN  [org.jboss.as.server.deployment] (MSC service thread 1-5) WFLYSRV0274: Excluded dependency com.fasterxml.jackson.core.jackson-annotations via jboss-deployment-structure.xml does not exist.
    14:06:10,189 INFO  [org.infinispan.PERSISTENCE] (MSC service thread 1-7) ISPN000556: Starting user marshaller 'org.wildfly.clustering.infinispan.marshalling.jboss.JBossMarshaller'
    14:06:10,209 INFO  [org.infinispan.CONTAINER] (MSC service thread 1-7) ISPN000128: Infinispan version: Infinispan 'Turia' 10.1.8.Final
    14:06:10,501 INFO  [org.jboss.as.clustering.infinispan] (ServerService Thread Pool -- 78) WFLYCLINF0002: Started client-mappings cache from ejb container
    14:06:10,557 INFO  [org.jboss.as.server] (management-handler-thread - 2) WFLYSRV0010: Deployed "jenkins" (runtime-name : "jenkins")
    ...
    

    Conclusion

    That’s all for Part 2! You've learned the basics of using the jcliff: module in a playbook, but there are still a few advanced use cases to explore. We'll do that in Part 3, the final installment in this series.

    Acknowledgment

    Special thanks to Andrew Block for reviewing this series of articles.

    Last updated: December 23, 2020

    Recent Posts

    • Exploring Llama Stack with Python: Tool calling and agents

    • Enhance data security in OpenShift Data Foundation

    • AI meets containers: My first step into Podman AI Lab

    • Live migrating VMs with OpenShift Virtualization

    • Storage considerations for OpenShift Virtualization

    Red Hat Developers logo LinkedIn YouTube Twitter Facebook

    Products

    • Red Hat Enterprise Linux
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform

    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
    © 2025 Red Hat

    Red Hat legal and privacy links

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

    Report a website issue