-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds a role to install java. The functionality is included in the `mirsg.infrastructure.tomcat` role but is needed as a standalone as a prerequisite to installing OMERO. - also added molecule test for the role, and a workflow for running the tests --------- Co-authored-by: Paul Smith <[email protected]>
- Loading branch information
1 parent
df344c3
commit 932caf8
Showing
11 changed files
with
114 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
--- | ||
name: Test install_java | ||
|
||
# yamllint disable-line rule:truthy | ||
on: | ||
pull_request: | ||
paths: | ||
- "molecule_configs/*" | ||
- "roles/install_java/**" | ||
- ".github/workflows/molecule.yml" | ||
- ".github/workflows/molecule-java.yml" | ||
|
||
jobs: | ||
molecule-java: | ||
uses: ./.github/workflows/molecule.yml | ||
with: | ||
tests-path: ansible_collections/mirsg/infrastructure/roles/install_java |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Ansible Role: mirsg.infrastructure.install_java | ||
|
||
A role to install and configure Java. | ||
|
||
## Role Variables | ||
|
||
`java_profile_d`: Defaults to "/etc/profile.d". | ||
|
||
`java_home`: Defaults to "/usr/lib/jvm/jre". | ||
|
||
`java_package`: Defaults to "java-1.8.0". | ||
|
||
`java_package_version`: Defaults to "devel". | ||
|
||
## Example Playbook | ||
|
||
Including an example of how to use your role (for instance, with variables | ||
passed in as parameters) is always nice for users too: | ||
|
||
```yaml | ||
- hosts: servers | ||
roles: | ||
- role: mirsg.infrastructure.install_java | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
java_profile_d: /etc/profile.d | ||
java_home: /usr/lib/jvm/jre | ||
java_package: java-1.8.0-openjdk | ||
java_package_version: devel |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
--- | ||
# test this scenario from the roles/install_java directory with the command | ||
# molecule --base-config ../../molecule_configs/centos7_base_config.yml test --scenario centos7 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
- name: Install Java | ||
hosts: all | ||
become: true | ||
gather_facts: true | ||
roles: | ||
- role: mirsg.infrastructure.install_java |
1 change: 1 addition & 0 deletions
1
roles/install_java/molecule/resources/inventory/group_vars/all.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
--- | ||
- name: Prepare - install sudo and Java 11 | ||
hosts: all | ||
gather_facts: true | ||
tasks: | ||
- name: Install sudo | ||
ansible.builtin.package: | ||
name: sudo | ||
state: present | ||
|
||
- name: Install Java 11 before the role installs Java 8 | ||
ansible.builtin.package: | ||
name: java-11-openjdk-devel | ||
state: present |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
--- | ||
- name: Verify correct java version is selected | ||
hosts: all | ||
tasks: | ||
- name: Get Java version | ||
ansible.builtin.shell: | ||
cmd: | | ||
set -o pipefail | ||
java -version 2>&1 | grep version | awk '{print $3}' | sed 's/"//g' | ||
register: java_version | ||
changed_when: false | ||
|
||
- name: Check the java version is correct | ||
ansible.builtin.assert: | ||
that: | ||
- java_version.stdout | split("_") | first is version('1.8.0') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
--- | ||
# test this scenario from the roles/install_java directory with the command | ||
# molecule --base-config ../../molecule_configs/rocky9_base_config.yml test --scenario rocky9 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
--- | ||
- name: Ensure correct Java version is installed - {{ java_package }} | ||
ansible.builtin.package: | ||
name: "{{ java_package }}-{{ java_package_version }}" | ||
state: installed | ||
|
||
- name: Set JAVA_HOME through shell script | ||
ansible.builtin.template: | ||
src: "java_home.sh.j2" | ||
dest: "{{ java_profile_d }}/java_home.sh" | ||
mode: "0644" | ||
when: java_home is defined and java_home != '' | ||
|
||
- name: Get info for java package directory | ||
ansible.builtin.stat: | ||
path: "/usr/lib/jvm/{{ java_package }}" | ||
register: java_package_info | ||
|
||
- name: Set the default java version - {{ java_package_info.stat.lnk_source }} | ||
community.general.alternatives: | ||
name: java | ||
path: "{{ java_package_info.stat.lnk_source }}/jre/bin/java" | ||
state: selected |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export JAVA_HOME="{{ java_home }}" |