DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations

Trending

  • RBAC With API Gateway and Open Policy Agent (OPA)
  • Auto-Scaling Kinesis Data Streams Applications on Kubernetes
  • [DZone Survey] Share Your Expertise for Our Database Research, 2023 Edition
  • What Is TTS and How Is It Implemented in Apps?
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Deployment
  4. Handling Deployments When Provisioning JBoss domain.xml (With Ansible)

Handling Deployments When Provisioning JBoss domain.xml (With Ansible)

Jakub Holý user avatar by
Jakub Holý
·
Feb. 28, 14 · Interview
Like (0)
Save
Tweet
Share
6.61K Views

Join the DZone community and get the full member experience.

Join For Free

It is tricky to manage JBoss with a provisioner such as Puppet or Ansible because its domain.xml contains not only rather static configuration but also sections that change quite often such as deployments. So how can we manage the static parts of domain.xml with f.ex. Ansible while still enabling developers to deploy at will via jboss-cli (and thus changing the <deployments> sections of the file)? Here is one possible solution, based on extracting the sections from the current file and merging them into the template.

We will use XSLT stylesheets to extract the deployments sections via xsltproc run as a command, storing their output into variables that will be then used in the domain.xml template. (xsltproc has been chosen since it already was on our servers.)

Here are the Ansible tasks themselves:

## JBoss merge deployment info from the existing domain.xml if any and copy the final domain.xml
# Note: <deployments> is added at 2 places to domain.xml whenever an app is deployed via JBoss CLI, we need to keep them
- name: Make sure xsltproc is installed
  yum: name=libxslt state=installed
  tags: jboss_configuration
 
- name: Copy XSLT stylesheets for domain.xml data extraction
  copy: src={{ item }} dest=/tmp
  with_items:
    - extract_domain_deployments.xslt
    - extract_servergroup_deployments.xslt
  tags: jboss_configuration
 
- name: Check if domain.xml already present
  stat: path=/opt/jboss/jboss-{{ jboss_version_short }}/domain/configuration/domain.xml
  register: domain_xml_stat
  tags: jboss_configuration
 
- name: Extract domain/deployments from domain.xml, if present
  command: /usr/bin/xsltproc /tmp/extract_domain_deployments.xslt /opt/jboss/jboss-{{ jboss_version_short }}/domain/configuration/domain.xml
  register: domain_deployments
  when: domain_xml_stat.stat.exists is defined and domain_xml_stat.stat.exists == true
  tags: jboss_configuration
 
- name: Extract server-groups//deployments from domain.xml, if present
  command: /usr/bin/xsltproc /tmp/extract_servergroup_deployments.xslt /opt/jboss/jboss-{{ jboss_version_short }}/domain/configuration/domain.xml
  register: servergroup_deployments
  when: domain_xml_stat.stat.exists is defined and domain_xml_stat.stat.exists == true
  tags: jboss_configuration
 
- name: Copying domain.xml configuration file
  template: src=domain.xml dest=/opt/jboss/jboss-{{ jboss_version_short }}/domain/configuration/
  notify: restart jboss-eap
  tags: jboss_configuration

The extract_domain_deployments.xslt stylesheet:

<xsl:stylesheet version="1.0"
    xmlns:j="urn:jboss:domain:1.5"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 
<!-- Output the domain/deployments element of domain.xml as is, without namespaces etc. -->
 
<xsl:output omit-xml-declaration="yes"/>
<xsl:template match="/">
  <xsl:apply-templates select="j:domain/j:deployments" />
</xsl:template>
 
<xsl:template match="*" name="identity">
  <xsl:element name="{name()}">
    <xsl:apply-templates select="node()|@*" />
  </xsl:element>
</xsl:template>
 
<!-- Copy content as is -->
<xsl:template match="node()|@*" priority="-2">
  <xsl:copy>
    <xsl:apply-templates select="node()|@*" />
  </xsl:copy>
</xsl:template>
 
</xsl:stylesheet>

The (quite similar) extract_servergroup_deployments.xslt stylesheet:

<xsl:stylesheet version="1.0"
    xmlns:j="urn:jboss:domain:1.5"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 
<!-- Output the domain/server-groups/server-group/deployments element of domain.xml as is, without namespaces etc. -->
 
<xsl:output omit-xml-declaration="yes"/>
<xsl:template match="/">
  <xsl:apply-templates select="j:domain/j:server-groups/j:server-group/j:deployments" />
</xsl:template>
 
<xsl:template match="*" name="identity">
  <xsl:element name="{name()}">
    <xsl:apply-templates select="node()|@*" />
  </xsl:element>
</xsl:template>
 
<!-- Copy content as is -->
<xsl:template match="node()|@*" priority="-2">
  <xsl:copy>
    <xsl:apply-templates select="node()|@*" />
  </xsl:copy>
</xsl:template>
 
</xsl:stylesheet>

The XSLT is so complex because we only have XSLT 1.0 and need to get rid of any namespace declarations that would normally be output. (SeeE. Lenz’ Too Many Namespaces for background and better options in XSLT 2.0).

Disadvantages

When we execute Ansible with –check –diff, it will always report that it would remove deployments from the file because it doesn’t run the extraction commands.

Update: According to "Marcus Meat Ramberg"  it might be possible to force the extract commands to run even during check using always_run (since v.1.3.). Thank you!

Ansible (software) JBoss

Published at DZone with permission of Jakub Holý, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Trending

  • RBAC With API Gateway and Open Policy Agent (OPA)
  • Auto-Scaling Kinesis Data Streams Applications on Kubernetes
  • [DZone Survey] Share Your Expertise for Our Database Research, 2023 Edition
  • What Is TTS and How Is It Implemented in Apps?

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com

Let's be friends: