fix: ensure correct jvm java_home is set

main
Guido Grazioli 2022-04-28 11:33:23 +02:00
parent 7028b068b6
commit e3bb10d901
No known key found for this signature in database
GPG Key ID: 22C8C31EF2BC093B
9 changed files with 24 additions and 8 deletions

View File

@ -6,4 +6,4 @@
collections: collections:
- middleware_automation.keycloak - middleware_automation.keycloak
roles: roles:
- middleware_automation.keycloak.keycloak - keycloak

View File

@ -60,13 +60,14 @@ Role Defaults
|`keycloak_jgroups_port`| jgroups cluster tcp port | `7600` | |`keycloak_jgroups_port`| jgroups cluster tcp port | `7600` |
|`keycloak_management_http_port`| Management port | `9990` | |`keycloak_management_http_port`| Management port | `9990` |
|`keycloak_management_https_port`| TLS management port | `9993` | |`keycloak_management_https_port`| TLS management port | `9993` |
|`keycloak_java_opts`| Additional JVM options | `-Xms1024m -Xmx2048m` |
|`keycloak_prefer_ipv4`| Prefer IPv4 stack and addresses for port binding | `True` | |`keycloak_prefer_ipv4`| Prefer IPv4 stack and addresses for port binding | `True` |
|`keycloak_config_standalone_xml`| filename for configuration | `keycloak.xml` | |`keycloak_config_standalone_xml`| filename for configuration | `keycloak.xml` |
|`keycloak_service_user`| posix account username | `keycloak` | |`keycloak_service_user`| posix account username | `keycloak` |
|`keycloak_service_group`| posix account group | `keycloak` | |`keycloak_service_group`| posix account group | `keycloak` |
|`keycloak_service_pidfile`| pid file path for service | `/run/keycloak.pid` | |`keycloak_service_pidfile`| pid file path for service | `/run/keycloak.pid` |
|`keycloak_jvm_package`| RHEL java package runtime | `java-1.8.0-openjdk-devel` | |`keycloak_jvm_package`| RHEL java package runtime | `java-1.8.0-openjdk-devel` |
|`keycloak_java_home`| JAVA_HOME of installed JRE, leave empty for using specified keycloak_jvm_package RPM path | `None` |
|`keycloak_java_opts`| Additional JVM options | `-Xms1024m -Xmx2048m` |
* Install options * Install options

View File

@ -21,7 +21,8 @@ keycloak_rhsso_enable: "{{ True if rhsso_rhn_id is defined and rhn_username is d
keycloak_offline_install: False keycloak_offline_install: False
### Install location and service settings ### Install location and service settings
keycloak_jvm_package: java-1.8.0-openjdk-devel keycloak_jvm_package: java-1.8.0-openjdk-headless
keycloak_java_home:
keycloak_dest: /opt/keycloak keycloak_dest: /opt/keycloak
keycloak_jboss_home: "{{ keycloak_rhsso_installdir if keycloak_rhsso_enable else keycloak_installdir }}" keycloak_jboss_home: "{{ keycloak_rhsso_installdir if keycloak_rhsso_enable else keycloak_installdir }}"
keycloak_config_dir: "{{ keycloak_jboss_home }}/standalone/configuration" keycloak_config_dir: "{{ keycloak_jboss_home }}/standalone/configuration"

View File

@ -1,4 +1,4 @@
--- ---
- name: "Restart {{ keycloak.service_name }}" - name: "Restart handler"
ansible.builtin.include_tasks: restart_keycloak.yml ansible.builtin.include_tasks: restart_keycloak.yml
listen: "restart keycloak" listen: "restart keycloak"

View File

@ -81,6 +81,9 @@ argument_specs:
default: "java-1.8.0-openjdk-devel" default: "java-1.8.0-openjdk-devel"
description: "RHEL java package runtime rpm" description: "RHEL java package runtime rpm"
type: "str" type: "str"
keycloak_java_home:
description: "JAVA_HOME of installed JRE, leave empty for using specified keycloak_jvm_package RPM path"
type: "str"
keycloak_dest: keycloak_dest:
# line 24 of keycloak/defaults/main.yml # line 24 of keycloak/defaults/main.yml
default: "/opt/keycloak" default: "/opt/keycloak"

View File

@ -31,7 +31,7 @@
dest: "{{ patch_archive }}" dest: "{{ patch_archive }}"
owner: "{{ keycloak_service_user }}" owner: "{{ keycloak_service_user }}"
group: "{{ keycloak_service_group }}" group: "{{ keycloak_service_group }}"
mode: 0750 mode: 0640
register: new_version_downloaded register: new_version_downloaded
when: when:
- not patch_archive_path.stat.exists - not patch_archive_path.stat.exists

View File

@ -9,6 +9,14 @@
notify: notify:
- restart keycloak - restart keycloak
- name: Determine JAVA_HOME for selected JVM RPM
shell: |
set -o pipefail
rpm -ql {{ keycloak_jvm_package }} | grep -Po '/usr/lib/jvm/.*(?=/bin/java$)'
args:
executable: /bin/bash
register: rpm_java_home
- name: "Configure sysconfig file for {{ keycloak.service_name }} service" - name: "Configure sysconfig file for {{ keycloak.service_name }} service"
become: yes become: yes
ansible.builtin.template: ansible.builtin.template:
@ -17,6 +25,8 @@
owner: root owner: root
group: root group: root
mode: 0644 mode: 0644
vars:
keycloak_rpm_java_home: "{{ rpm_java_home.stdout }}"
notify: notify:
- restart keycloak - restart keycloak

View File

@ -17,7 +17,7 @@ checkEnvVar() {
# for testing outside systemd # for testing outside systemd
. /etc/sysconfig/keycloak . /etc/sysconfig/keycloak
readonly KEYCLOAK_HOME={{ keycloak_jboss_home }} readonly KEYCLOAK_HOME={{ keycloak.home }}
readonly KEYCLOAK_BIND_ADDRESS=${KEYCLOAK_BIND_ADDRESS} readonly KEYCLOAK_BIND_ADDRESS=${KEYCLOAK_BIND_ADDRESS}
readonly KEYCLOAK_HTTP_PORT=${KEYCLOAK_HTTP_PORT} readonly KEYCLOAK_HTTP_PORT=${KEYCLOAK_HTTP_PORT}
readonly KEYCLOAK_HTTPS_PORT=${KEYCLOAK_HTTPS_PORT} readonly KEYCLOAK_HTTPS_PORT=${KEYCLOAK_HTTPS_PORT}
@ -27,7 +27,7 @@ readonly KEYCLOAK_PIDFILE={{ keycloak_service_pidfile }}
set -u set -u
if [ ! -d "${KEYCLOAK_HOME}" ]; then if [ ! -d "${KEYCLOAK_HOME}" ]; then
echo "KEYCLOAK_HOME (${KEYCLOAK_HOME}) is not a director or does not exists." echo "KEYCLOAK_HOME (${KEYCLOAK_HOME}) is not a directory or does not exists."
exit 1 exit 1
fi fi

View File

@ -1,6 +1,7 @@
# {{ ansible_managed }} # {{ ansible_managed }}
JAVA_OPTS='{{ keycloak_java_opts }}' JAVA_OPTS='{{ keycloak_java_opts }}'
JBOSS_HOME={{ keycloak_jboss_home }} JAVA_HOME={{ keycloak_java_home | default(keycloak_rpm_java_home, true) }}
JBOSS_HOME={{ keycloak.home }}
KEYCLOAK_BIND_ADDRESS={{ keycloak_bind_address }} KEYCLOAK_BIND_ADDRESS={{ keycloak_bind_address }}
KEYCLOAK_HTTP_PORT={{ keycloak_http_port }} KEYCLOAK_HTTP_PORT={{ keycloak_http_port }}
KEYCLOAK_HTTPS_PORT={{ keycloak_https_port }} KEYCLOAK_HTTPS_PORT={{ keycloak_https_port }}