WildFly server configuration with Ansible collection for JCliff, Part 3
fetched at December 21, 2020

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.

Share

The post WildFly server configuration with Ansible collection for JCliff, Part 3 appeared first on Red Hat Developer.

Visit Link
🤖 CodeKN.com

Follow our Twitter bot for more updates.