How to Create Custom Ansible Wildfly Module – Part 3

Sharing is caring!

Introduction

Welcome to Ansible Wildfly Module part 3. Well, after creating a server, it is time to configure the JVM parameter. Basically, Wildfly host already has default JVM parameter. So, in practical, setting JVM is not a must, but sometimes it is needed.

Take note here, this how-to only works in domain mode as well.

Use Case

In this use case, I want to leverage Wildfly host with these specifications: JVM for a server with minimum heap size 512MB, maximum heap size 1024MB.

Well, maybe you have already noticed that there are permgen parameters, which in Java 8 are not needed anymore. But, currently the properties is there, so just add this parameters as a precaution. Maybe someone is using JDK 7.

And of course, if we can add JVM then we have to provide the remove functionality as well.

Cheat Sheet

This how-to is running on JDK 8, Wildfly 10, Python 2.7 and Ansible 2.1.2. Moreover, these are JBoss-CLI commands for JVM purpose.

Step by step

Step 1 – Create Python File

As usual, create a python file and name it jcli_jvm.py. Then put the file under library folder. Also do not forget to add hash bang and import statement.

Step 2 – Create Function to Check JVM Existence

Just as all previous posts, before creating or removing JVM, we need to have a functionality in order to validate whether the JVM has already been created or not. Also, one of the reasons is to determine the Ansible changed flag as well.

Note: this similar with part 1 and part 2.

  1. We have six dictionary keys, which are jboss_homeserver_group_namecontroller_host, controller_portuser and password. These keys will be defined in the main method.
  2. Whenever the result contains WFLYCTL0216, it is assumed that the JVM with the given name already created.
  3. Whenever the result contains WFLYPRT0053, it is assumed that the remote host cannot be reached.
Step 3 – Create Functions for JVM Maintenance

In this step, we need to create to functions. First is for creating JVM and setting the parameters, then attach to specific Wildfly Server. We will give it a name jvm_present. Secondly, the function to remove JVM from it and name it jvm_absent.

jvm_present

jvm_absent

Note:

  1. There are 8 additional field keys, which are: host, server_config_name, jvm_name, heap_size, max_heap_size, permgen_sizejvm_options and max_permgen_size.
  2. After setting the new JVM parameter, we need to reload the server in order to make it works.
Step 4 – Define Main Function

Now it is time to define main function. Collect all the dictionary keys and the state keys, then put them into main function. And define the main function as well.

Step 5 – play.yml

It is time to add this module into your play.yml.

Note: I snipped the playbook only for JVM part. If you want to see the whole parts, you can see in previous post.

Execute the play.yml then you will see similar result:

Execute playbook
Execute playbook
Wildfly Web Console
Wildfly Web Console

Conclusion

Now we have successfully attach JVM with custom parameters into Wildfly Server. The next part is about deploying our WAR or EAR into the it. Have a blessed day!

Author: ru rocker

I have been a professional software developer since 2004. Java, Python, NodeJS, and Go-lang are my favorite programming languages. I also have an interest in DevOps. I hold professional certifications: SCJP, SCWCD, PSM 1, AWS Solution Architect Associate, and AWS Solution Architect Professional.

Leave a Reply

Your email address will not be published. Required fields are marked *