Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework migration role to support (downstream) use of EAP8 #280

Merged
merged 2 commits into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions roles/wildfly_migration/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
---
wildfly_migration_environment_props: templates/environment.properties.j2
wildfy_migration_require_privileges_escalation: true
wildfly_migration_java_home: '/usr/lib/jvm/jre'
wildfly_migration_jdk_package_name: 'java-17-openjdk-devel'
wildfly_migration_jdk_package_skip_install: False
wildfly_migration_server_tool_home: "{{ target_wildfly_home }}"
wildfly_migration_tool_bin_folder: 'bin'
wildfly_migration_tool_bin_script_name: 'jboss-server-migration.sh'
wildfly_migration_server_tool_path_to_script: "{{ wildfly_migration_server_tool_home }}/{{ wildfly_migration_tool_bin_folder }}/{{ wildfly_migration_tool_bin_script_name }}"
wildfly_migration_server_tool_subfolder_to_configuration: '/migration'
wildfly_migration_server_tool_env_properties_file: 'configuration/environment.properties'
wildfly_migration_path_to_env_properties: "{{ wildfly_migration_server_tool_home }}{{ wildfly_migration_server_tool_subfolder_to_configuration }}/{{ wildfly_migration_server_tool_env_properties_file }}"
wildfly_migration_config_files: 'standalone.xml,standalone-full.xml'
wildfly_migration_tool_configuration_template: 'templates/environment.properties.j2'
wildfly_migration_require_privileges_escalation: True
107 changes: 106 additions & 1 deletion roles/wildfly_migration/meta/argument_specs.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,113 @@
argument_specs:
main:
options:
# line 2 of defaults/main.yml
target_wildfly_home:
required: True
description: "Path on the target to the server's home to migrate to"
type: "str"
previous_wildfly_home:
required: True
description: "Path on the target to the server's home to migrate from"
type: "str"
wildfly_migration_environment_props:
default: "templates/environment.properties.j2"
description: "Template to configure the migration tool"
type: "str"
wildfy_migration_require_privileges_escalation:
default: True
description: "Indicate if the server migration tool requires privileges escalation"
type: "str"
wildfly_migration_server_tool_home:
default: "{{ target_wildfly_home }}"
description: "Path to the server migration tool"
type: "str"
wildfly_migration_tool_bin_folder:
default: ""
description: "Folder, relatives to wildfly_migration_server_tool_home where the server migration tool script resides"
type: "str"
wildfly_migration_tool_bin_script_name:
default: "jboss-server-migration.sh"
description: "Name of the script lauching the server migration tool"
type: "str"
wildfly_migration_server_tool_path_to_script:
default: "{{ wildfly_migration_server_tool_home }}/{{ wildfly_migration_tool_bin_folder }}/ {{ wildfly_migration_tool_bin_script_name }}"
description: "Path to the script launching the server migration tool"
type: "str"
wildfly_migration_server_tool_subfolder_to_configuration:
default: "/migration"
description: "Subfolder, relatrives to server migration"
type: "str"
wildfly_migration_server_tool_env_properties_file:
default: "configuration/environment.properties"
description: "Relative path of the main configuration file of the server migration tool"
type: "str"
wildfly_migration_path_to_env_properties:
description: "Absolute path to the main configuration"
default: "{{ wildfly_migration_server_tool_home }}{{ wildfly_migration_server_tool_subfolder_to_configuration }}/{{ wildfly_migration_server_tool_env_properties_file }}"
type: "str"
wildfly_migration_config_files:
default: 'standalone.xml,standalone-full.xml'
description: "Name(s) of the configuration files to migrate to the new server"
type: "str"
wildfly_migration_tool_configuration_template:
default: 'templates/environment.properties.j2'
description: "Relative path to the jinja template for the server tool migration main configuration file"
type: "str"
wildfly_migration_require_privileges_escalation:
default: True
description: "Indicates whether or the migration server tool requires root privileges to run"
type: "str"
wildfly_migration_java_home:
default: "/usr/lib/jvm/jre"
description: "Path to the JAVA HOME to be used by the server migration tool"
type: "str"
wildfly_migration_jdk_package_name:
default: "java-17-openjdk-devel"
description: "Name of the RPM package to install for the JVM used by the server migration tool"
type: "str"
wildfly_migration_jdk_package_skip_install:
default: False
description: "Indicates if the install check of the RPM package for the JVM of the migration server tool can be skipped"
type: "bool"
wildfly_migration_jdk_package_install_requires_privileges_escalation:
default: True
description: "Indicates if the install of the RPM for the JVM on the target executing the migration server tool can be skipped"
type: "bool"
wildfly_migration_jdk_package_install_requires_privileges_escalation_user:
default: "root"
description: "Specify the user to become for privileges escalation for JVM install"
type: "str"
downstream:
options:
eap_enable:
default: True
description: "Enable install of Red Hat JBoss EAP"
type: "bool"
eap_migration_server_tool_path_to_archive:
default: "{{ eap_migration_server_tool_download_dir }}/jboss-eap-{{ eap_version | default('8.0.0') }}-server-migration.zip"
description: "Path to the Red Hat provided archive for the server migration tool"
type: "str"
eap_migration_server_tool_product_id:
default: 106310
description: "Red Hat ID for the server migration tool archive"
type: "int"
eap_migration_server_tool_download_dir:
default: "/opt"
description: "Path to the folder where the server migration archive is downloaded"
type: "str"
eap_migration_server_tool_install_dir:
default: "/opt"
description: "Directory where to install the server migration tool - if not provided with EAP"
type: "str"
eap_migration_server_tool_home:
default: "{{ (eap_version != '8.0.0') | ternary(target_eap_home,eap_migration_server_tool_install_dir + '/jboss-server-migration') }}"
description: "Path to the server migration tool home - if not provided with EAP"
type: "str"
eap_migration_tool_bin_folder:
default: "{{ (eap_version != '8.0.0') | ternary('/bin','') }}"
description: "Indicates which subfolder, relative to eap_migration_server_tool_home, the server migration script resides."
type: "str"
eap_migration_server_tool_subfolder_to_configuration:
default: "{{ (eap_version != '8.0.0') | ternary('/migration', '') }}"
description: "Subfolder, relatives to eap_migration_server_tool_home, where are located server migration tool configurations files"
type: "str"
45 changes: 45 additions & 0 deletions roles/wildfly_migration/tasks/install/rhn.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---
- name: "Ensure required parameters are provided."
ansible.builtin.assert:
that:
- eap_migration_server_tool_path_to_archive is defined and eap_migration_server_tool_path_to_archive | length > 0
- eap_migration_server_tool_product_id is defined > 0
quiet: True
fail_msg: "Missing required parameters."

- name: "Esclade privileges if needed"

Check warning on line 10 in roles/wildfly_migration/tasks/install/rhn.yml

View workflow job for this annotation

GitHub Actions / ci / linter (3.11, 2.16)

key-order[task]

You can improve the task key order to: name, become, become_user, block
block:
- name: "Load metadata on server migration tool archive for EAP8"
ansible.builtin.stat:
path: "{{ eap_migration_server_tool_path_to_archive }}"
register: eap_migration_archive_md

- name: "Ensure server migration tool for EAP8 has been downloaded"
redhat.runtimes_common.product_download:
client_id: "{{ rhn_username }}"
client_secret: "{{ rhn_password }}"
product_id: "{{ eap_migration_server_tool_product_id }}"
dest: "{{ eap_migration_server_tool_path_to_archive }}"
no_log: "{{ omit_rhn_output | default(true) }}"
run_once: true
when:
- eap_migration_archive_md is defined
- eap_migration_archive_md.stat is defined
- eap_migration_archive_md.stat.exists is defined
- not eap_migration_archive_md.stat.exists

- name: "Ensure that server migration tool home folder exists"
ansible.builtin.file:
path: "{{ eap_migration_server_tool_install_dir }}"
state: directory
mode: "0755"

- name: "Ensure server migration tool for EAP8 has been decompressed"
ansible.builtin.unarchive:
src: "{{ eap_migration_server_tool_path_to_archive }}"
dest: "{{ eap_migration_server_tool_install_dir }}"
remote_src: "{{ eap_migration_remote_src | default('yes') }}"
creates: "{{ eap_migration_server_tool_path_to_script }}"

become: "{{ eap_migration_server_tool_install_require_privileges_escalation | default('yes') }}"
become_user: "{{ eap_migration_server_tool_install_require_privileges_escalation_user | default('root') }}"
57 changes: 19 additions & 38 deletions roles/wildfly_migration/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,47 +7,28 @@
quiet: True
fail_msg: "Missing required parameters."

- name: "Escalate privileges if required"
become: "{{ wildfy_migration_require_privileges_escalation | default('true') }}"
block:
- name: "Determine path to migration tool."
ansible.builtin.set_fact:
migration_tool: "{{ target_wildfly_home }}/bin/jboss-server-migration.sh"
- name: "Ensure that the required JVM has been installed on target: {{ wildfly_migration_jdk_package_name }}"
become: "{{ wildfly_migration_jdk_package_install_requires_privileges_escalation | default('yes') }}"
become_user: "{{ wildfly_migration_jdk_package_install_requires_privileges_escalation_user | default('root') }}"
ansible.builtin.dnf:
name: "{{ wildfly_migration_jdk_package_name }}"
state: present

- name: "Load metadata on migration tool full path."
ansible.builtin.stat:
path: "{{ migration_tool }}"
register: migration_tool_state
- name: "Ensure Server Migration Tool is installed on target if EAP8 is the target"
ansible.builtin.include_tasks: install/rhn.yml
when:
- eap_enable is defined and eap_enable
- eap_version is defined and eap_version == '8.0.0'

- name: "Check that path to migration tool is valid."
ansible.builtin.assert:
that:
- migration_tool_state is defined
- migration_tool_state.stat is defined
- migration_tool_state.stat.exists is defined
- migration_tool_state.stat.exists
- migration_tool_state.stat.isreg is defined
- migration_tool_state.stat.isreg
quiet: True
fail_msg: "Invalid path to migration tool: {{ migration_tool }}."
- name: "Escalate privileges if required"
become: "{{ wildfly_migration_require_privileges_escalation | default('true') }}"
block:

- name: "Ensure migration configuration is deployed"
- name: "Ensure that the Migration Toolkit configuration have been updated to include: {{ wildfly_migration_config_files }}"
ansible.builtin.template:
src: "{{ wildfly_migration.environment_props }}"
dest: "{{ target_wildfly_home }}/migration/configuration/environment.properties"
owner: "{{ wildfly_user | default('root') }}"
group: "{{ wildfly_group | default('root') }}"
mode: '0644'
src: "{{ wildfly_migration_tool_configuration_template }}"
dest: "{{ wildfly_migration_path_to_env_properties }}"
mode: "0644"

- name: "Run migration tool"
ansible.builtin.command: "{{ migration_tool }} --non-interactive --source {{ previous_wildfly_home }} --environment {{ target_wildfly_home }}/migration/configuration/environment.properties"
register: migration_results
changed_when:
- '"Migration Result: SUCCESS" in migration_results.stdout'

- name: "Display results of migration"
ansible.builtin.debug:
msg: "{{ migration_results }}"
changed_when: False
when:
- '"Migration Result: SUCCESS" in migration_results.stdout'
ansible.builtin.include_tasks: run_server_migration.yml
35 changes: 35 additions & 0 deletions roles/wildfly_migration/tasks/prerun_checks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
- name: "Load metadata on migration tool full path."
ansible.builtin.stat:
path: "{{ wildfly_migration_server_tool_path_to_script }}"
register: migration_tool_state

- name: "Check that path to migration tool is valid."
ansible.builtin.assert:
that:
- migration_tool_state is defined
- migration_tool_state.stat is defined
- migration_tool_state.stat.exists is defined
- migration_tool_state.stat.exists
- migration_tool_state.stat.isreg is defined
- migration_tool_state.stat.isreg
quiet: True
fail_msg: "Invalid path to migration tool: {{ wildfly_migration_server_tool_path_to_script }}."

- name: "Ensure all files belong to the appropriate user: {{ wildfly_user }}/{{ wildfly_group }}"
ansible.builtin.file:
path: "{{ folder }}"
recurse: yes
owner: "{{ wildfly_user }}"
group: "{{ wildfly_group }}"
changed_when: False
loop:
- "{{ previous_wildfly_home }}"
- "{{ target_wildfly_home }}"
- "{{ wildfly_migration_server_tool_home }}"
loop_control:
loop_var: folder
when:
- not wildfly_migration_skip_file_ownership_check is defined
- wildfly_user is defined and wildfly_user | length > 0
- wildfly_group is defined and wildfly_group | length > 0
24 changes: 24 additions & 0 deletions roles/wildfly_migration/tasks/run_server_migration.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
- name: "Verify that Server Migration tool can run"
ansible.builtin.include_tasks: prerun_checks.yml

- name: "Lookup value of PATH on target"
ansible.builtin.set_fact:
target_path: "{{ lookup('env', 'PATH') }}"

- name: "Run migration tool"
become: yes
become_user: wildfly
ansible.builtin.command: "{{ wildfly_migration_server_tool_path_to_script }} --non-interactive --source {{ previous_wildfly_home }} --environment {{ wildfly_migration_path_to_env_properties }} --target {{ target_wildfly_home }}"
register: migration_results
changed_when: False
failed_when: False
environment:
JAVA_HOME: "{{ wildfly_migration_java_home }}"
PATH: "{{ wildfly_migration_java_home }}{{ target_path }}"

- name: "Fails if command did not produced any result"
ansible.builtin.fail:
var: "{{ ansible_failed_task | default('Migration command failed to produce any results') }}"
when:
- not migration_results is defined
4 changes: 2 additions & 2 deletions roles/wildfly_migration/templates/environment.properties.j2
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ report.xml.fileName=migration-report.xml

#server.source.standalone.serverDir=standalone
#server.source.standalone.configDir=configuration
server.source.standalone.configFiles=standalone.xml,standalone-full.xml,jboss_eap.xml
server.source.standalone.configFiles={{ wildfly_migration_config_files }}
#server.source.standalone.serverDir=standalone
#server.source.standalone.configDir=configuration

Expand Down Expand Up @@ -45,7 +45,7 @@ extensions.includes=
#management.setup-http-upgrade.socket-binding.management-https.update-port.skip=true

# a list with module names to migrate
modules.includes={{ wildfly_driver_module_name }}
modules.includes=
# a list with module names to not migrate
modules.excludes=
#modules.migrate-modules-requested-by-configuration.skip=true
Expand Down
3 changes: 0 additions & 3 deletions roles/wildfly_migration/vars/main.yml

This file was deleted.

2 changes: 1 addition & 1 deletion roles/wildfly_utils/tasks/apply_cp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
register: local_path
delegate_to: localhost

- name: "Check local downloaded archive: {{ patch_bundle }}"
- name: "Check local downloaded archive"
ansible.builtin.stat:
path: "{{ local_path.stat.path }}/{{ patch_bundle }}"
register: local_archive_path
Expand All @@ -57,7 +57,7 @@

- name: Determine patch versions list
ansible.builtin.set_fact:
filtered_versions: "{{ rhn_products.results | map(attribute='file_path') | select('match', '^[^/]*/jboss-eap-.*[0-9]*[.][0-9]*[.][0-9]*.*$') | map('regex_replace','[^/]*/jboss-eap-([0-9]*[.][0-9]*[.][0-9]*)-.*','\\1' ) | list | unique }}"

Check warning on line 60 in roles/wildfly_utils/tasks/apply_cp.yml

View workflow job for this annotation

GitHub Actions / ci / linter (3.11, 2.16)

jinja[spacing]

Jinja2 spacing could be improved: {{ rhn_products.results | map(attribute='file_path') | select('match', '^[^/]*/jboss-eap-.*[0-9]*[.][0-9]*[.][0-9]*.*$') | map('regex_replace','[^/]*/jboss-eap-([0-9]*[.][0-9]*[.][0-9]*)-.*','\1' ) | list | unique }} -> {{ rhn_products.results | map(attribute='file_path') | select('match', '^[^/]*/jboss-eap-.*[0-9]*[.][0-9]*[.][0-9]*.*$') | map('regex_replace', '[^/]*/jboss-eap-([0-9]*[.][0-9]*[.][0-9]*)-.*', '\1') | list | unique }}
when: eap_patch_version is not defined or eap_patch_version | length == 0
delegate_to: localhost
run_once: true
Expand Down
Loading