Skip to content

Commit 81ac1e9

Browse files
authored
Add support for alternative JDK installation options in prereq_jdk role (#300)
Signed-off-by: rsuplina <[email protected]>
1 parent a7128f3 commit 81ac1e9

File tree

6 files changed

+124
-0
lines changed

6 files changed

+124
-0
lines changed

roles/prereq_jdk/README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ The role will:
1313
- For JDKs installed from Cloudera's repository, the role will ensure that any missing symbolic links are created to support a consistent JDK installation path.
1414
- Compare JDK against the support matrix at [supportmatrix.cloudera.com/](https://supportmatrix.cloudera.com) for the specified versions of Cloudera Manager and Cloudera Runtime.
1515

16+
- The primary JDK (as defined by `jdk_provider` and `jdk_version`) will always be set as the system default and linked to `/usr/bin/java`.
17+
- Any additional JDKs installed via `additional_jdk_packages` will not be set as the system default. To use these alternative JDKs, you must reference their explicit paths in scripts or applications (e.g., `/usr/lib/jvm/zulu21-jdk/bin/java`).
1618
# Requirements
1719

1820
- Root or `sudo` privileges are required to install packages and modify system-wide configuration files.
@@ -35,6 +37,9 @@ None.
3537
| `jdk_security_paths_override` | `bool` | `False` | `False` | Flag to control behavior when multiple `java.security` files are found in the specified paths. If `true`, the role will continue with JCE changes even if multiple files are found. If `false`, the role will fail, requiring a more specific path list. |
3638
| `cloudera_manager_version` | `str` | `True` | | The version of Cloudera Manager to validate against. |
3739
| `cloudera_runtime_version` | `str` | `True` | | The version of Cloudera Runtime to validate against. |
40+
| `additional_jdk_packages` | `list` of `str` | `False` | | List of alternative JDK packages to install (e.g., `openjdk-21-jdk`, `zulu21-jdk`). |
41+
| `additional_jdk_repository` | `str` | `False` | | Repository URL for the alternative JDK. |
42+
| `additional_jdk_key` | `str` | `False` | | GPG key URL for the alternative JDK repository. |
3843

3944
# Example Playbook
4045

@@ -70,6 +75,18 @@ None.
7075
jdk_security_paths_override: false
7176
cloudera_manager_version: "7.11.3"
7277
cloudera_runtime_version: "7.1.9"
78+
79+
- name: Set up OpenJDK 17 as default and Azul Zulu 21 as alternative
80+
ansible.builtin.import_role:
81+
name: cloudera.exe.prereq_jdk
82+
vars:
83+
cloudera_manager_version: "7.11.3"
84+
cloudera_runtime_version: "7.1.9"
85+
jdk_version: 17
86+
additional_jdk_packages:
87+
- zulu21-jdk
88+
additional_jdk_repository: "https://cdn.azul.com/zulu/bin/zulu-repo-1.0.0-1.noarch.rpm"
89+
additional_jdk_key: "https://repos.azul.com/azul-repo.key"
7390
```
7491
7592
# License

roles/prereq_jdk/defaults/main.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,6 @@ jdk_security_paths_override: false
2222

2323
cloudera_manager_version: "{{ undef(hint='Please specify the Cloudera Manager version') }}"
2424
cloudera_runtime_version: "{{ undef(hint='Please specify the Cloudera Runtime version') }}"
25+
# additional_jdk_packages:
26+
# additional_jdk_repository:
27+
# additional_jdk_key:

roles/prereq_jdk/meta/argument_specs.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ argument_specs:
2020
- Set up the Java Development Kit (JDK), optionally installing the JDK itself.
2121
- For JDK 9 and below, optionally enable the Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy.
2222
- If the JDK is installed from the Cloudera repo, add any missing symlinks.
23+
- The primary JDK (as defined by jdk_provider and jdk_version) will always be set as the system default and linked to /usr/bin/java.
24+
- Any additional JDKs installed via additional_jdk_packages will not be set as the system default; to use them, explicit paths must be referenced in scripts or applications.
2325
author: Cloudera Labs
2426
version_added: "3.0.0"
2527
options:
@@ -68,3 +70,19 @@ argument_specs:
6870
description: Version of Cloudera Runtime for validation testing
6971
type: str
7072
required: true
73+
additional_jdk_packages:
74+
description:
75+
- List of alternative JDK packages to install (e.g., openjdk-21-jdk, zulu21-jdk).
76+
type: list
77+
elements: str
78+
required: false
79+
additional_jdk_repository:
80+
description:
81+
- Repository URL for the alternative JDK.
82+
type: str
83+
required: false
84+
additional_jdk_key:
85+
description:
86+
- GPG key URL for the alternative JDK repository.
87+
type: str
88+
required: false

roles/prereq_jdk/tasks/RedHat.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Copyright 2025 Cloudera, Inc. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
---
16+
- name: Import alternative JDK GPG key for RPM
17+
ansible.builtin.rpm_key:
18+
state: present
19+
key: "{{ additional_jdk_key }}"
20+
when: additional_jdk_repository is defined and additional_jdk_key is defined
21+
22+
- name: Install alternative JDK repository
23+
ansible.builtin.dnf:
24+
name: "{{ additional_jdk_repository }}"
25+
state: present
26+
when: additional_jdk_repository is defined
27+
28+
- name: Install alternative JDK packages
29+
ansible.builtin.package:
30+
name: "{{ item }}"
31+
state: present
32+
loop: "{{ additional_jdk_packages }}"

roles/prereq_jdk/tasks/Rocky.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Copyright 2025 Cloudera, Inc. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
---
16+
- name: Import alternative JDK GPG key for RPM
17+
ansible.builtin.rpm_key:
18+
state: present
19+
key: "{{ additional_jdk_key }}"
20+
when: additional_jdk_repository is defined and additional_jdk_key is defined
21+
22+
- name: Install alternative JDK repository
23+
ansible.builtin.dnf:
24+
name: "{{ additional_jdk_repository }}"
25+
state: present
26+
when: additional_jdk_repository is defined
27+
28+
- name: Install alternative JDK packages
29+
ansible.builtin.package:
30+
name: "{{ item }}"
31+
state: present
32+
loop: "{{ additional_jdk_packages }}"

roles/prereq_jdk/tasks/main.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,4 +130,26 @@
130130
)
131131
)
132132
133+
- name: Install alternative JDKs if additional_jdk_packages is set
134+
when: additional_jdk_packages is defined and additional_jdk_packages | length > 0
135+
block:
136+
- name: Install alternative JDKs (OS-specific)
137+
ansible.builtin.include_tasks: "{{ ansible_facts['os_family'] }}.yml"
138+
139+
- name: Find an existing JDK installation
140+
ansible.builtin.stat:
141+
path: /usr/bin/java
142+
register: jdk_dir
143+
144+
- block:
145+
- name: Set java alternative back to JDK
146+
community.general.alternatives:
147+
name: java
148+
path: "{{ jdk_dir.stat.lnk_source | default('/usr/bin/java') }}"
149+
150+
- name: Set javac alternative back to JDK
151+
community.general.alternatives:
152+
name: javac
153+
path: "{{ (jdk_dir.stat.lnk_source | regex_replace('java$', 'javac')) if jdk_dir.stat.islnk else '/usr/bin/javac' }}"
154+
when: jdk_dir.stat.exists
133155
# https://docs.cloudera.com/cdp-private-cloud-base/7.1.9/installation/topics/cdpdc-manually-installing-openjdk.html

0 commit comments

Comments
 (0)