How to Create Custom Ansible Wildfly Module – Part 4

Sharing is caring!

Introduction

Hi there! Welcome to the last part for this long journey. Oops, I mean long posts regarding Ansible Wildfly Module. The reason why I posted such a multiple how-to is to reach the ultimate goal, which is the deployment. So yeah, it is time to set up the deployment.

Deployment

Application server, in this case Wildfly, almost has no meaning without deploying your WAR or EAR into it. Because deployment means making your software system available for use. Also deployment involves several activities which sometimes inter related between them. Therefore, imagine we can make all of those things automatically. It will make your life easier, won’t it?

Use Case

I had a feeling that you already knew what are the use cases. Well, I know you were right. The use cases are only deploy and undeploy artifact (WAR or EAR) into and out of Wildfly.

Cheat Sheet

This tutorial is running on JDK 8, Wildfly 10, Ansible 2.1.2 and python 2.7. Also, here are JBoss CLI commands to deploy and undeploy built artifact.

But now is a little bit special. The deployment is not only for domain mode, but for standalone mode as well. So let’s start the step by step!

Step by Step

Step 1 – Create Python File

As usual, create a file and give it a name jcli_deploy.py. Put it into library folder. Then add hash bang and import statement as well.

Step 2 – Create Function to Check Deployment Existence

We have to create function to check whether the artifact has already deployed or not. Besides the need of Ansible changed status, this function will determine whenever we need to put force flag while executing deployment command.

Note:

  1. We have six dictionary keys, which are jboss_home, server_group_name, controller_host, controller_port, user and password. These keys will be defined in the main method.
  2. Whenever the result contains WFLYCTL0216, it is assumed that the deployment has already existed.
  3. Whenever the result contains WFLYPRT0053, it is assumed that the remote host cannot be reached.
Step 3 – Create Functions for Deployment

Based on use cases, we will define two functions. The first function is deployment_present, which will be used to deploy artifact to Wildfly. Another one is deployment_absent to undeploy artifact from Widlfly.

deployment_present

deployment_absent

Note:

  1. There are four additional field dictionary keys. Those keys are:
    • server_group_name: to deploy artifact to all hosts in the same server group. This keys only valid for domain mode.
    • server_mode: select the deployment for standalone or domain mode
    • artifact_dir: artifact directory
    • artifact: artifact name
  2. Deployment command will return WFLYDC0074 if the deployment fails. Whenever we received that error, we will set Ansible state to error.
Step 4 – Define Main Function

After collecting all keys and state key, we can create the main function.

Step 5 – play.yml

Update the play.yml by adding jcli_deploy module.

Execute the playbook and you will see similar result:

Ansible Wildfly Module
Ansible Wildfly Module
Wildflya Management Console
Wildflya Management Console

Conclusion

After reaching the last post, now we can automate most of the things we need in order to make an automation related to Wildfly. Once we have things automated, especially related with artifact deployment, now we can move to another big thing, which is continuous deployment.

I will bring this topic somewhere in the future. Meanwhile, I have a contributor who like to share his thought about IT world as well. Hope to see him soon. Have a nice 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.

4 thoughts on “How to Create Custom Ansible Wildfly Module – Part 4”

  1. Great writeup!

    Have you thought of contributing this to the Ansible project?
    Would be create to see this as an official core or extras module!
    Especially as WildFly is closely tied to RedHat, just like Ansible … you stand a fair chance 🙂

    1. Hi..

      Thank you for reading this blog.

      Initially, when I wrote this article, I was thinking to contribute to Ansible project. But, as time goes, this idea slightly fades away.

      Well, it starts to pop up again. I will use this as a reminder and encouragement 🙂
      Once again, thank you for your support.

  2. Hi ,
    Thanks for sharing precious information .We are awaiting for continuous deployment article with Ansible .Please let me know if you provide online training for Ansible .

    Thank you ,
    Kumar .

    1. Hi Kumar

      I am glad that my blog did help.
      Currently I am writing blog only for sharing what I have learn so far.
      I don’t have any online training.

      However I put your request into my article queue.
      I have done it actually with combination of maven, jenkins and ansible.
      It is just a simple deployment, without pipeline.
      You can check on my repo https://github.com/ru-rocker/vagrant-ci.

Leave a Reply

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