ansible-middleware / wildfly

A collection of roles to help install, setup and maintain Java JEE appserver Wildfly
GNU General Public License v2.0
12 stars 22 forks source link

Allow for installing/enabling JBoss EAP XP (Microprofile Extensions) #159

Open InfoSec812 opened 11 months ago

InfoSec812 commented 11 months ago
SUMMARY

It would be useful if the wildfly_install/eap_install could also install the XP extensions and enable them

Here's an example I have used to do this:

- name: Retrieve XP manager jar download using JBoss Network API
  redhat.runtimes_common.product_search:
    client_id: "{{ rhn_username }}"
    client_secret: "{{ rhn_password }}"
    product_category: "appplatform.xp"
  register: rhn_products
  no_log: "{{ omit_rhn_output | default(true) }}"
  delegate_to: localhost
  run_once: yes
  tags:
    - eap_xp
  when:
    - eap_xp_install | bool

- name: "Determine XP manager jar from search results."
  ansible.builtin.set_fact:
    rhn_filtered_products: "{{ rhn_products.results | selectattr('file_path', 'match', '[^/]*/jboss-eap-xp-' + eap_xp_version + '-manager.jar$') }}"
  delegate_to: localhost
  run_once: yes
  tags:
    - eap_xp
  when: eap_xp_install | bool

- name: Debug XP manager jar
  ansible.builtin.debug:
    msg: "Search Results: {{ rhn_products.results }}"
  delegate_to: localhost
  run_once: yes
  tags:
    - eap_xp
  when: eap_xp_install | bool

- name: Download XP manager jar
  redhat.runtimes_common.product_download: # noqa risky-file-permissions delegated, uses controller host user
    client_id: "{{ rhn_username }}"
    client_secret: "{{ rhn_password }}"
    product_id: "{{ (rhn_filtered_products | last).id }}"
    dest: "/tmp/jboss-eap-xp-manager.jar"
  no_log: "{{ omit_rhn_output | default(true) }}"
  delegate_to: localhost
  run_once: yes
  tags:
    - eap_xp
  when: eap_xp_install | bool

- name: "Determine XP patch zip from search results."
  ansible.builtin.set_fact:
    rhn_filtered_products: "{{ rhn_products.results | selectattr('file_path', 'match', '[^/]*/jboss-eap-xp.*-patch.zip$') }}"
  delegate_to: localhost
  run_once: yes
  tags:
    - eap_xp
  when: eap_xp_install | bool

- name: Download XP patch zip
  redhat.runtimes_common.product_download: # noqa risky-file-permissions delegated, uses controller host user
    client_id: "{{ rhn_username }}"
    client_secret: "{{ rhn_password }}"
    product_id: "{{ (rhn_filtered_products | last).id }}"
    dest: "/tmp/jboss-eap-xp-patch.zip"
  no_log: "{{ omit_rhn_output | default(true) }}"
  delegate_to: localhost
  run_once: yes
  tags:
    - eap_xp
  when: eap_xp_install | bool

- name: Copy EAP XP Manager To Target
  ansible.builtin.copy:
    src: "{{ eap_xp_manager_local_file | default('/tmp/jboss-eap-xp-manager.jar') }}"
    dest: "{{ eap_xp_manager_local_file | default('/tmp/jboss-eap-xp-manager.jar') }}"
    owner: "{{ eap_user }}"
    group: "{{ eap_group }}"
    mode: 755
  tags:
    - eap_xp
  when: eap_xp_install | bool

- name: Copy EAP XP Patch To Target
  ansible.builtin.copy:
    src: "{{ eap_xp_patch_local_file | default('/tmp/jboss-eap-xp-patch.zip') }}"
    dest: "{{ eap_xp_patch_local_file | default('/tmp/jboss-eap-xp-patch.zip') }}"
    owner: "{{ eap_user }}"
    group: "{{ eap_group }}"
    mode: 755
  tags:
    - eap_xp
  when: eap_xp_install | bool

- name: Check EAP XP Status
  ansible.builtin.shell:
    cmd: "java -jar {{ eap_xp_manager_local_file | default('/tmp/jboss-eap-xp-manager.jar') }} status --jboss-home={{ eap_install_workdir }}/jboss-eap-7.4 | grep 'Available commands' | awk -F':' '{print $2}'"
  register: eap_xp_status
  tags:
    - eap_xp
  when: eap_xp_install | bool

- name: Debug XP Manager Status
  ansible.builtin.debug:
    msg: "XP Manager Status: {{ eap_xp_status }}"
    verbosity: 0
  tags:
    - eap_xp
  when: eap_xp_install | bool

- name: Run EAP XP setup if needed
  ansible.builtin.shell:
    cmd: "java -jar {{ eap_xp_manager_local_file | default('/tmp/jboss-eap-xp-manager.jar') }} setup --jboss-home={{ eap_install_workdir }}/jboss-eap-7.4 --accept-support-policy"
  tags:
    - eap_xp
  when:
    - eap_xp_install | bool
    - eap_xp_status.stdout is search('setup') 

- name: Install EAP XP Extension
  ansible.builtin.shell:
    cmd: "java -jar {{ eap_xp_manager_local_file | default('/tmp/jboss-eap-xp-manager.jar') }} patch-apply --jboss-home={{ eap_install_workdir }}/jboss-eap-7.4 --patch={{ eap_xp_patch_local_file | default('/tmp/jboss-eap-xp-patch.zip') }}"
  tags:
    - eap_xp
  when:
    - eap_xp_install | bool
    - eap_xp_status.stdout is search('patch-apply')
  notify: Restart JBoss EAP
ISSUE TYPE
InfoSec812 commented 11 months ago

It would also be necessary to enable the various extensions/subsystems. For example, to enable metrics-smallrye, you need to:

  1. Enable the config-smallrye extension - jboss-cli.sh -c '/extension=org.wildfly.extension.microprofile.config-smallrye:add
  2. Reload JBoss - jboss-cli.sh -c 'reload'
  3. Enable the metrics-smallrye extension - jboss-cli.sh -c '/extension=org.wildfly.extension.microprofile.metrics-smallrye:add
  4. Reload JBoss - jboss-cli.sh -c 'reload'
  5. Enable the config subsystem: jboss-cli.sh -c '/subsystem=microprofile-config-smallrye:add'
  6. Enable the metrics subsystem: jboss-cli.sh -c '/subsystem=microprofile-metrics-smallrye:add'
  7. Reload JBoss - jboss-cli.sh -c 'reload'