-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add java role #59
Add java role #59
Changes from all commits
4ae07d5
79f7b60
3885af1
8b80b88
70edf2e
edaee08
b159ee9
38f2d92
a43c871
b5688c0
05e0e23
4e07e61
16ad3ea
ddd0ec6
e2c8493
f7e479b
54fb0db
6d08ba6
d307db9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 |
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 | ||
``` |
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 |
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 |
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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
--- | ||
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 |
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' | ||
Comment on lines
+7
to
+9
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the output from
The output from the command on line 9 is:
|
||
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') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove the |
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 |
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 }}" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export JAVA_HOME="{{ java_home }}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this empty file is required otherwise molecule complains that the inventory doesn't exist