I'm attempting to write an Ansible script to upgrade a Payara instance to a newer one, by taking a backup of the domains on the current installation, nuking it, installing the new version of Payara and then restoring the backup that was just made to it. This appears to be the recommended way to upgrade Payara.
I've made considerable progress laboring on this, partially from code I've already written to run a fresh install of Payara and partially from code I've written new for this script, but have run into a roadblock on the last part. Because it's possible that a given Payara instance may have more than one domain in it, I've had to figure out how to use loops in Ansible and I still don't fully grasp how they work. I've successfully done the first half of the process (extracting out backups of all the domains) by doing a find of the directory Payara stores the domains in and looping over it, but the restore has introduced a headache because the filename is unique every time - it will be the only file in that folder, but even after analyzing it for some time I can't see how you'd reference what'd effectively be two loops at once.
My code (cut down for relevancy) so far:
- name: Get list of Payara domains
find:
paths: /opt/{{ payara_folder }}/glassfish/domains
file_type: directory
register: result_of_find
- name: Run backup-domain on each of the Payara domains
command: "/opt/{{ payara_folder }}/bin/asadmin backup-domain --backupDir /tmp/payara_backup {{ item.path | basename }}"
with_items: "{{ result_of_find.files }}"
- name: Run restore-domain on each of the Payara domains
command: "/opt/{{ payara_folder }}/bin/asadmin restore-domain --fileName /tmp/payara_backup/{{ item.path | basename }}/**NAME OF BACKUP FILE HERE** --backupDir /tmp/payara_backup {{ item.path | basename }}"
with_items: "{{ result_of_find.files }}"
As mentioned, tasks 1 & 2 work perfectly fine, but I'm struggling with task 3: Payara's backup extraction kicks out a name along the lines of domain_yyyy_mm_dd_v00001.zip
. I considered adding a task that goes through and renames all the backups to something like backup.zip
between steps 2 and 3 given that they're all in separate sub-directories but a) I don't know if Payara will accept a file with a different naming layout (I don't see why it wouldn't?) and b) this only moves the problem of identifying the filenames to a different task.
Any suggestions on how I go about this?