Transitioning from an RPM workflow to a .tar (or .tar.gz) distribution simplifies build pipelines and decouples deployment from host-level package managers (rpm/yum).
The breakdown below details the modifications required for both your Gradle build and your Ansible deployment step.
1. Gradle Project Changes
What to Remove:
-
RPM Plugins: Remove any OS packaging plugins (e.g.,
id 'nebula.ospackage',com.netflix.nebula.ospackage). -
RPM Configuration Tasks: Delete all
ospackage,buildRpm, orrpmtasks frombuild.gradle. -
Artifactory RPM Publications: Remove the RPM artifact publishing configuration inside your
publishingblock.
What to Add:
Apply Gradle’s native distribution plugin or use a standard Tar task, and update the Artifactory maven-publish or ivy publishing setup.
Example build.gradle snippet:
plugins {
id 'java'
id 'distribution' // Generates .tar and .zip distribution archives
id 'maven-publish' // For pushing to Artifactory
}
// Option A: Configure standard distribution structure
distributions {
main {
distributionBaseName = 'my-app'
contents {
into('lib') {
from configurations.runtimeClasspath
from tasks.named('jar')
}
into('resources') {
from 'src/main/resources'
}
}
}
}
// Option B: Custom Tar Task (if you prefer explicit naming/compression)
tasks.register('buildAppTar', Tar) {
archiveBaseName = 'my-app'
archiveVersion = project.version.toString()
archiveExtension = 'tar.gz'
compression = Compression.GZIP
into('lib') {
from configurations.runtimeClasspath
from tasks.named('jar')
}
into('resources') {
from 'src/main/resources'
}
}
// Update Artifactory publishing to push the TAR and Manifest
publishing {
publications {
mavenTar(MavenPublication) {
// Attach the TAR archive generated by distribution or custom task
artifact(tasks.named('distTar')) {
extension 'tar.gz'
}
// Attach your manifest file artifact if generated separately
artifact(file("${buildDir}/reports/manifest.json")) {
classifier 'manifest'
extension 'json'
}
}
}
}
2. Ansible Playbook Changes
What to Remove:
-
RPM Installation Tasks: Remove tasks using
ansible.builtin.yum,ansible.builtin.dnf, oransible.builtin.packageto install the.rpmfile. -
RPM Query / Cleanup Steps: Remove tasks checking
rpm -qaor removing old package versions via package managers.
What to Add:
Use ansible.builtin.unarchive to fetch or unpack the .tar.gz directly into the target application path.
- name: Ensure application target directory exists
ansible.builtin.file:
path: /opt/my-app
state: directory
owner: appuser
group: appuser
mode: '0755'
- name: Retrieve Manifest from Artifactory
ansible.builtin.get_url:
url: "{{ artifactory_url }}/my-app-{{ app_version }}-manifest.json"
dest: /opt/my-app/manifest.json
url_username: "{{ artifactory_user }}"
url_password: "{{ artifactory_password }}"
mode: '0644'
- name: Download and unpack TAR directly onto host
ansible.builtin.unarchive:
src: "{{ artifactory_url }}/my-app-{{ app_version }}.tar.gz"
dest: /opt/my-app/
remote_src: yes # Downloads directly from Artifactory URL on target host
owner: appuser
group: appuser
mode: '0755'
Key Operational Differences
-
Permissions & Ownership: RPM automatically handles system permissions during installation via the RPM spec. With
.tar, explicitly passowner,group, andmodeattributes in the Ansibleunarchiveandfiletasks. -
Symlinking / Versioning: Because
.tarextraction overrides or adds to target directories rather than replacing a package database entry, consider extracting each deployment into a versioned folder (e.g.,/opt/my-app/releases/1.2.3/) and swapping a symlink (/opt/my-app/current) for atomic rollbacks.
Top comments (0)