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 3

December 21, 2020
Romain Pelisse
Related topics:
JavaDevOpsLinux
Related products:
Red Hat Enterprise Linux

Share:

    Welcome to the final installment in this three-part series about using Ansible Collection for JCliff to manage WildFly or Red Hat JBoss Enterprise Application Platform (JBoss EAP) instances. Previously, we've discussed installing and configuring the JCliff Ansible collection and using its basic features. In this article, we discuss advanced options available with the project's latest release. Without further ado, let's dive in!

    Using custom JCliff rules

    JCliff supports tweaking and configuring a large number of WildFly subsystems. Many of these have yet to be integrated into the Ansible collection. However, it is still possible to leverage those extra features. In this section, we’ll show you how to implement a custom ruleset to leverage JCliff's full capabilities inside Ansible.

    Configuring WildFly's mail subsystem

    Let’s say we wanted to configure a mail session inside a WildFly configuration. Currently, no mail element is available for the jcliff: module. Instead, we can use a script provided by the JCliff project:

    {
      "mail" => {
         "mail-session" => {
            "testSession" => {
               "from" => "a@b.com",
               "jndi-name" => "java:jboss/mail/testSession",
               "server" => {
                  "smtp" => {
                     "outbound-socket-binding-ref" => "mail-smtp",
                     "ssl" => false
                   }
               }
             }
         }
      }
    }

    We can provide this snippet to Ansible collection for JCliff to execute and thus configure our WildFly server's mail subsystem. First, let’s create a directory for the JCliff configuration file and download the example:

    vars:
    ...
      jcliff_config_files_dir: /opt/jcliff
    ...
         - name: Create directory for jcliff rules
           file:
             name: "{{ jcliff_config_files_dir }}"
             state: directory
      
         - name: Download mail.test configuration file for JCLiff
           uri:
             url: https://raw.githubusercontent.com/bserdar/jcliff/master/testscripts/mail.test
             dest: "{{ jcliff_config_files_dir }}/mail.test"
             creates: "{{ jcliff_config_files_dir }}/mail.test"
    

    Next, we configure the jcliff: module to execute the files available in this ruleset directory:

    ...
    - jcliff:
       wfly_home: "{{ jboss_home }}"
       rule_file: "{{ jcliff_config_files_dir }}"
       subsystems:
    ...

    Note: The next version of Ansible collection for JCliff will include a mail element.

    Verifying the new configuration

    It is easy to verify that the configuration change has happened as expected. WildFly's log file should contain a message mentioning the newly bound mail session:

    ...
    14:38:36,372 INFO  [org.jboss.as.mail.extension] (MSC service thread 1-6) WFLYMAIL0001: Bound mail session [java:jboss/mail/testSession]
    ...

    For more information about the mail-session configuration, we can enter a simple query using WildFly's JBoss CLI:

    /subsystem=mail/mail-session=testSession:read-resource
    {
    
        "outcome" => "success",
        "result" => {
            "debug" => false,
            "from" => "a@b.com",
            "jndi-name" => "java:jboss/mail/testSession",
            "custom" => undefined,
            "server" => {"smtp" => undefined}
        },
        "response-headers" => {"process-state" => "reload-required"}
    }
    

    Note that this last change requires reloading WildFly's configuration. If you've deployed WildFly on the system as a service, you can also ask Ansible to restart it. If WildFly is not deployed as a service, you can still use the JBoss CLI in Ansible to reload:

    - name: "Restart WildFly"
      command: "{{ jboss_home }}/bin/jboss-cli.sh --connect --command=':reload'"
    

    Troubleshooting JCliff

    Of course, not everything works as expected out of the box. At times, you might need to analyze and investigate what is really happening under the covers. In this section, we’ll highlight how to troubleshoot issues when using JCliff with Ansible.

    First, bear in mind that Ansible only generates the configuration files required by JCliff and runs the command-line tool. As a result, very little can go wrong when using Ansible collection for JCliff. At worst, you might encounter invalid paths or similar human errors. Using Ansible with verbose logging (such as -vvvv) should help you identify such problems.

    If you run into challenges specific to the jcliff: module, it's often best to run the tool outside of Ansible to see what’s happening. In this case, your first step is to retrieve the configuration file generated by Ansible and ensure the content is correct.

    The generated configuration files for JCliff are deleted after each Ansible run. To access them, you must instruct Ansible not to delete those files. Set the following parameter before running Ansible:

    export ANSIBLE_KEEP_REMOTE_FILES=1
    

    When the jcliff: module fails, you should be able to locate the configuration file based on the failing subsystem's name. For instance, if you have issues with the automation of the JDBC driver deployment, you should look for a file named drivers-0.jcliff.yml.

    Once you have located the file, run jcliff with the option -v , and pass it the following configuration file:

    $ jcliff -v ~/.ansible/tmp/ansible-tmp-1597756555.46-5332-269490407528192//drivers-0.jcliff.yml
    

    If the problem is not revealed as part of the JCliff execution, the set of JBoss CLI queries executed should still give you an idea about what is happening. You can then connect to the WildFly instance (using the JBoss CLI script provided with the server) and directly run those queries. Doing that will most likely uncover the underlying issue.

    Conclusion

    Before releasing Ansible collection for JCliff, considerable plumbing was required to automate the setup and configuration of a WildFly instance. Even if you used JCliff directly, you still needed a few configuration files. Without JCliff, you were required to design, write, and test hundreds of lines of JBoss CLI scripts. Some developers tried to work around this limitation by using templating for automation. Unfortunately, that workaround caused issues if the configuration file was modified outside of Ansible.

    Ansible collection for JCliff resolves these issues. It is concise and integrates smoothly into Ansible. As a developer, you can state the desired configuration in a few lines, just as you would do for any other resources managed by Ansible.

    We hope you've enjoyed this series getting to know Ansible collection for JCliff, and that you will give the tool a try the next time you need to configure a WildFly or JBoss EAP instance.

    Acknowledgment

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

    Last updated: December 20, 2020

    Recent Posts

    • More Essential AI tutorials for Node.js Developers

    • How to run a fraud detection AI model on RHEL CVMs

    • How we use software provenance at Red Hat

    • Alternatives to creating bootc images from scratch

    • How to update OpenStack Services on OpenShift

    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

    Red Hat legal and privacy links

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

    Report a website issue