Deploy JBoss Enterprise Application Platform (EAP) using Ansible Automation Platform (AAP) [Part 1]
In this article, I will be recording my experience with deployment of standalone JBoss EAP to 2 different servers from the Ansible Automation Platform. I will show how to configure Ansible Automation Platform for this process. I will also be showing how to deploy simple applications on JBoss on 1 of the servers after installation from AAP.
Click here for Part 2 of the Series
Note:
This post does not utilize the wildfly deployment and thus would be going through all the configurations.
The post will be referring to be my GitHub repository here, but I will include the code with modifications for this post.
The simulation was done on 32 GB RAM, Intel i7 laptop, with Fedora Workstation installed. The code will be edited with Visual Studio Code.
Prerequisites:
- Existing hardware of 16GB RAM.
- Pre-installed Ansible Automation Platform. Standalone Controller Installation will suffice. How to create virtual machine and how to install is written here.
- Virtual Machines. I have simulated a 3 tier JBoss Application deployed from AAP. Hence, there will be 4 other Virtual Machines other than the AAP controller virtual machine(8GB RAM). These are application1 (4 GB RAM), application2 (4GB RAM), databank (8gb RAM), loadbalancer (4GB RAM).
- All the virtual machines will utilize 4 vCPUs (This should not be affected by your existing actual hardware).
Note:
For simplicity and ease of showcasing how AAP can be used to deploy JBoss Application across servers, only application1, application2 and AAP controller virtual machines are required for this post.
To downsize the RAM required, only application1 and AAP controller VM are needed for your simulation, in the case of crashing by fully utilizing the RAM in a laptop of 16GB RAM. (Utilizing 12GB RAM)
Preparing Playbooks
First of all you will start with an empty project folder/directory. I will be using roles and will cover it briefly in this post. Create 2 directories/folders in the project folder/directory, namely roles and collections.
Collections
In the collections folder/directory, create a requirements.yml file:
There will be 2 main packages required in this installation:
- Community.General Collection
- Ansible.Posix Collection
Ansible Automation Platform will detect the collections to install from this file.
Code:
---
collections:
- community.general
- ansible.posix
Note:
Please take note of the indentations in the playbook as you follow along in this blog post. If there is a tab/space specified, then do take note to put a single tab/space for the relevant lines to avoid error. Avoid any unnecessary spaces at the end of each line.
Hosts File
This is a plain text document. In this file, there will be specifications for the hosts groups. It will look like this with multiple servers in multiple groups:
[webservers]
apache ansible_host=192.123.124.1 ansible_connection=ssh
[appservers]
eap1 ansible_host=192.123.124.2 ansible_connection=ssh
eap2 ansible_host=192.123.124.3 ansible_connection=ssh
[databank]
eapdb ansible_host=192.123.124.4 ansible_connection=ssh
Here there will be host groups namely webservers, appservers and databank. In here, the hosts are named, ip addresses are identified. AAP will be connecting to these servers using SSH.
(Webservers and Databank will not be utilized in this post)
For deployment of JBoss across 2 servers, it will be:
[appservers]
eap1 ansible_host=192.123.124.2 ansible_connection=ssh
eap2 ansible_host=192.123.124.3 ansible_connection=ssh
Ansible Configuration File
In the project directory folder, create an ansible configuration file, namely ansible.cfg file.
I have directed the inventory to the hosts text file. For ease of use, I have set host_key_checking to False to prevent ssh key errors.
I have also allowed privilege escalation to allow for AAP to modify the hosts as root. This allows access for package installation e.g. JBoss EAP.
Overall YAML file
There will be a yaml file to access the role to deploy tasks for JBoss Installation.
---
- name: Configure JBoss EAP Server
hosts: appservers
roles:
- eap
Creating Roles
Under the View tab at the top of visual studio code, go into the terminal and go into the roles folder:
cd roles
You can go into the roles folder in project directory from the Command Prompt as well. Run the Ansible Galaxy command (Install the ansible package if prompted):
ansible-galaxy init eap
This will create a role directory structure for the role eap. Under /vars folder/directory in main.yml:
/vars/main.yml:
---
# vars file for roles/eap
jboss_eap_user: jboss-eap
jboss_eap_group: jboss-eap
eap_deploy_dir: /opt
eap_version: 7.4
eap_link: https://www.dropbox.com/s/ukq5tbrfegkz313/jboss-eap-7.4.0.zip?dl=1
eap_archive: jboss-eap-7.4.0.zip
eap_home: "{{ eap_deploy_dir }}/jboss-eap-{{eap_version}}"
eap_all: "{{ eap_deploy_dir }}/jboss-eap-*/"
rhel_initd: /etc/init.d
jboss_eap_service_conf_dir: "/etc/default"
app_url: 'https://drive.google.com/uc?export=download&id=1w9ss5okctnjUvRAxhPEPyC7DmbUwmbhb'
app_name: 'info-1.1.war'
I have hosted a Jboss installation zipped file on dropbox which will be retrieved by the playbook to install on the servers. Google drive link would contain a sample war application file to be deployed on the EAP server. The application will be deployed by the EAP role as well on the Jboss Standalone server.
/tasks/main.yml
Packages required to install JBoss will be downloaded through the playbook.
The service will be stopped if there is a JBoss service running for the updates. The JBoss Server will be installed and configured through the playbook. Installation files downloaded will be cleared up after installation.
For the command modules, I have specify my username and password in the command directly in the playbook for ease of use. Ansible Vault files can be utilized for this process, or a credential can be encrypted under the Credentials tab in the Ansible Automation Platform.
---
# tasks file for roles/eap
- name: Install JBoss Requirements
ansible.builtin.dnf:
name: java-1.8.0-openjdk-devel, unzip, initscripts, hostname
state: present
- name: Check if service exists
stat: path=/etc/init.d/jboss-eap-rhel.sh
register: service_status
- name: Ensure EAP service is stopped
when: service_status.stat.exists
ignore_errors: true
service:
name: jboss-eap-rhel
state: stopped
- name: Create JBoss EAP Group
group:
name: "{{ jboss_eap_group }}"
system: yes
state: present
gid: "{{ jboss_eap_group_gid | default('400') }}"
- name: Create JBoss EAP User
user:
name: "{{ jboss_eap_user }}"
comment: "JBoss EAP User"
uid: "{{ jboss_eap_user_uid | default('400') }}"
group: "{{ jboss_eap_group }}"
home: "{{ eap_deploy_dir }}"
- name: Clean EAP directory
file:
state: absent
path: "{{ eap_home }}"
- name: Remove EAP directories (for different versions)
file:
state: absent
path: "{{ eap_all }}"
- name: "Obtains JBoss repository"
get_url:
url: "{{ eap_link }}"
dest: "{{ eap_deploy_dir }}"
- name: Unarchive EAP
unarchive:
src: "{{ eap_deploy_dir }}/{{ eap_archive }}"
dest: "{{ eap_deploy_dir }}"
owner: "{{ jboss_eap_user }}"
group: "{{ jboss_eap_group }}"
remote_src: yes
- name: Clear JBoss Zip File
file:
state: absent
path: "{{ eap_deploy_dir }}/{{ eap_archive }}"
- name: Create symlink
file:
src: "{{eap_home}}"
dest: "/opt/jboss-eap"
state: link
- name: Modify JBoss EAP Configuration File
lineinfile:
state: present
path: "{{ eap_home }}/bin/init.d/jboss-eap.conf"
regexp: "{{ item.regexp }}"
line: "{{ item.line }}"
with_items:
- {regexp: "^# JBOSS_USER=", line: "JBOSS_USER=jboss-eap"}
- {regexp: "^# JBOSS_CONFIG=", line: "JBOSS_CONFIG=standalone-ha.xml"}
- {regexp: "^# JBOSS_OPTS=", line: "JBOSS_OPTS=\"-b 0.0.0.0 -bprivate `hostname -i` -Djboss.node.name={{ inventory_hostname }}\""}
- name: Copy JBoss Service Configuration File
copy:
src: "{{ eap_home }}/bin/init.d/jboss-eap.conf"
dest: "{{ jboss_eap_service_conf_dir }}/"
remote_src: True
owner: "{{ jboss_eap_user }}"
group: "{{ jboss_eap_group }}"
- name: Copy JBoss EAP Service File
copy:
src: "{{ eap_home }}/bin/init.d/jboss-eap-rhel.sh"
dest: "{{ rhel_initd }}"
remote_src: True
owner: "{{ jboss_eap_user }}"
group: "{{ jboss_eap_group }}"
mode: 0755
- name: Enable EAP service
service:
name: jboss-eap-rhel.sh
enabled: yes
- name: Start EAP service
service:
name: jboss-eap-rhel
state: started
- name: Create Admin Users juhan on each application
command: "sh {{ eap_home }}/bin/add-user.sh juhan password"
- name: Ensures webapp War file has been retrieved from the url
get_url:
url: "{{ app_url }}"
dest: "{{ eap_deploy_dir }}"
- name: Deploy the war file on each standalone server (replace if deployed)
command: "sh {{ eap_home }}/bin/jboss-cli.sh -u=juhan -p=password --controller=localhost:9990 --connect --command='deploy {{ eap_deploy_dir }}/{{ app_name }} --force'"
- name: Clear JBoss Zip File
file:
state: absent
dest: "{{ eap_deploy_dir }}/{{ app_name }}"
Now, the playbook is ready to be ran on Ansible Automation Platform. Ansible Automation Platform will need to be configured to run this project. This will be specified in Part 2 of this series.