Skip to main content
Redhat Developers  Logo
  • 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 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

    • OpenShift AI learning
    • 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.
    • Explore the solution
  • 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.
    • 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

    • Access product downloads to start building and testing right away.
    • 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.
    • Explore the benefits

WildFly server configuration with Ansible collection for JCliff, Part 2

December 3, 2020
Romain Pelisse
Related topics:
JavaDevOpsLinux

    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

    • Confidential virtual machine storage attack scenarios

    • Introducing virtualization platform autopilot

    • Integrate zero trust workload identity manager with Red Hat OpenShift GitOps

    • Best Practice Configuration and Tuning for Linux and Windows VMs

    • Red Hat UBI 8 builders have been promoted to the Paketo Buildpacks organization

    Red Hat Developers logo LinkedIn YouTube Twitter Facebook

    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