diff --git a/roles/wildfly_migration/defaults/main.yml b/roles/wildfly_migration/defaults/main.yml index 89d8b7a4..57e9cd4f 100644 --- a/roles/wildfly_migration/defaults/main.yml +++ b/roles/wildfly_migration/defaults/main.yml @@ -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 diff --git a/roles/wildfly_migration/meta/argument_specs.yml b/roles/wildfly_migration/meta/argument_specs.yml index cd010f0b..4711cc3f 100644 --- a/roles/wildfly_migration/meta/argument_specs.yml +++ b/roles/wildfly_migration/meta/argument_specs.yml @@ -1,8 +1,105 @@ 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" + downstream: + options: + eap_enable: + default: True + description: "Enable install of Red Hat JBoss EAP" + type: "bool" + eap_migration_server_tool_path_to_archive: + default: "/opt/jboss-eap-{{ eap_version }}-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_download_node: + default: "localhost" + description: "Hostname of the node used to download the server migration archive provided by Red Hat Customer Portal" + 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,'/opt/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" diff --git a/roles/wildfly_migration/tasks/install/rhn.yml b/roles/wildfly_migration/tasks/install/rhn.yml new file mode 100644 index 00000000..9f85283d --- /dev/null +++ b/roles/wildfly_migration/tasks/install/rhn.yml @@ -0,0 +1,43 @@ +--- +- 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: "Load metadata on Migration Toolkit archive for EAP8" + ansible.builtin.stat: + path: "{{ eap_migration_server_tool_path_to_archive }}" + register: eap_migration_archive_md + delegate_to: "{{ eap_migration_server_download_node | default(omit) }}" + +- name: "Ensure Migration Toolkit 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) }}" + delegate_to: "{{ eap_migration_server_download_node | default(omit) }}" + 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: "Compute archive is local to control or remote" + ansible.builtin.set_fact: + eap_migration_remote_src: no + when: + - eap_migration_server_download_node is defined + - eap_migration_server_download_node == 'localhost' + +- name: "Ensure Migration Toolkit 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 }}" diff --git a/roles/wildfly_migration/tasks/main.yml b/roles/wildfly_migration/tasks/main.yml index 6e66d35e..6d98bdb5 100644 --- a/roles/wildfly_migration/tasks/main.yml +++ b/roles/wildfly_migration/tasks/main.yml @@ -7,47 +7,25 @@ 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: "Load metadata on migration tool full path." - ansible.builtin.stat: - path: "{{ migration_tool }}" - register: migration_tool_state +- name: "Ensure that the required JVM has been installed on target: {{ wildfly_migration_jdk_package_name }}" + ansible.builtin.dnf: + name: "{{ wildfly_migration_jdk_package_name }}" + state: present - - 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: "Ensure Server Migration Tool is installed on target if wildfly8 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: "Ensure migration configuration is deployed" - 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' +- name: "Ensure that the Migration Toolkit configuration have been updated to include: {{ wildfly_migration_config_files }}" + ansible.builtin.template: + src: "{{ wildfly_migration_tool_configuration_template }}" + dest: "{{ wildfly_migration_path_to_env_properties }}" + mode: "0644" +- name: "Escalate privileges if required" + become: "{{ wildfly_migration_require_privileges_escalation | default('true') }}" + block: - 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 diff --git a/roles/wildfly_migration/tasks/prerun_checks.yml b/roles/wildfly_migration/tasks/prerun_checks.yml new file mode 100644 index 00000000..a54619a2 --- /dev/null +++ b/roles/wildfly_migration/tasks/prerun_checks.yml @@ -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 diff --git a/roles/wildfly_migration/tasks/run_server_migration.yml b/roles/wildfly_migration/tasks/run_server_migration.yml new file mode 100644 index 00000000..cbaccebd --- /dev/null +++ b/roles/wildfly_migration/tasks/run_server_migration.yml @@ -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 diff --git a/roles/wildfly_migration/templates/environment.properties.j2 b/roles/wildfly_migration/templates/environment.properties.j2 index c45e2911..6494a7d3 100644 --- a/roles/wildfly_migration/templates/environment.properties.j2 +++ b/roles/wildfly_migration/templates/environment.properties.j2 @@ -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 @@ -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 diff --git a/roles/wildfly_migration/vars/main.yml b/roles/wildfly_migration/vars/main.yml deleted file mode 100644 index b78cb458..00000000 --- a/roles/wildfly_migration/vars/main.yml +++ /dev/null @@ -1,3 +0,0 @@ ---- -wildfly_migration: - environment_props: "{{ wildfly_migration_environment_props }}"