Skip to content
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

feat: add corretto java package #5

Merged
merged 3 commits into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .github/workflows/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,31 @@ jobs:
matrix:
include:
- distro: 'amazonlinux-2023'
playbook: 'converge.yml'
- distro: 'debian-11'
playbook: 'converge.yml'
- distro: 'debian-11'
playbook: 'converge-corretto.yml'
- distro: 'debian-12'
playbook: 'converge.yml'
- distro: 'debian-12'
playbook: 'converge-corretto.yml'
- distro: 'rockylinux-8'
playbook: 'converge.yml'
- distro: 'rockylinux-8'
playbook: 'converge-corretto.yml'
- distro: 'rockylinux-9'
playbook: 'converge.yml'
- distro: 'rockylinux-9'
playbook: 'converge-corretto.yml'
- distro: 'ubuntu-20.04'
playbook: 'converge.yml'
- distro: 'ubuntu-20.04'
playbook: 'converge-corretto.yml'
- distro: 'ubuntu-22.04'
playbook: 'converge.yml'
- distro: 'ubuntu-22.04'
playbook: 'converge-corretto.yml'

steps:
- name: 'Checkout the codebase'
Expand All @@ -53,3 +72,4 @@ jobs:
PY_COLORS: '1'
ANSIBLE_FORCE_COLOR: '1'
TAG: ${{ matrix.distro }}
MOLECULE_PLAYBOOK: ${{ matrix.playbook }}
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ Requirements
- Supported version of Ansible: 2.12 and highter.
- Supported platforms:
- Amazon Linux
- all
- 2
- 2023
- Debian
- 10
- 11
Expand All @@ -26,7 +27,15 @@ Requirements
Role Variables
--------------

- `java_package` The Java package name (see default values in `vars/*.yml`).
- `java_distribution` The Java package distribution type. Available values are: `openjdk` (default), `corretto`.
- `java_openjdk_package_name` The OpenJDK package name (see default values in `vars/*.yml`).
- `java_corretto_repository_mirror_url` The Amazon Corretto repository mirror.
- `https://yum.corretto.aws` (for RedHat based distributions)
- `https://apt.corretto.aws` (for Debian based distributions)
- `java_corretto_repository_gpgkey_url` URL to Amazon Corretto GPG key file.
- `https://yum.corretto.aws/corretto.key` (for RedHat based distributions)
- `https://apt.corretto.aws/corretto.key` (for Debian based distributions)
- `java_corretto_package_name` The Amazon Corretto package name (see default values in `vars/*.yml`).
- `java_home` The JAVA_HOME environment variable is used to specify the location of the Java executable files.

Dependencies
Expand Down
13 changes: 12 additions & 1 deletion defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
---
java_package: '{{ _default_java_package }}'
# Install Java
java_distribution: 'openjdk'

# Install the OpenJDK package
java_openjdk_package_name: '{{ _java_openjdk_package_name }}'

# Install the Java package from the Amazon Corretto repository
java_corretto_repository_mirror_url: '{{ _java_corretto_repository_mirror_url }}'
java_corretto_repository_gpgkey_url: '{{ _java_corretto_repository_gpgkey_url }}'
java_corretto_package_name: '{{ _java_corretto_package_name }}'

# Configure the JAVA_HOME environment variable
java_home: ''
3 changes: 2 additions & 1 deletion meta/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ galaxy_info:
platforms:
- name: 'Amazon Linux'
versions:
- 'all'
- '2'
- '2023'
- name: 'Debian'
versions:
- 'buster'
Expand Down
6 changes: 6 additions & 0 deletions molecule/default/converge-corretto.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
- name: 'Converge'
hosts: all
roles:
- role: antmelekhin.java
java_distribution: 'corretto'
2 changes: 2 additions & 0 deletions molecule/default/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,7 @@ platforms:
pre_build_image: true
provisioner:
name: 'ansible'
playbooks:
converge: ${MOLECULE_PLAYBOOK:-converge.yml}
verifier:
name: 'ansible'
2 changes: 1 addition & 1 deletion molecule/default/verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@

- name: 'The Java version output'
ansible.builtin.debug:
var: __java_version_check.stdout_lines[0]
var: __java_version_check.stdout_lines[1]
32 changes: 31 additions & 1 deletion tasks/install-Debian.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,37 @@
---
- name: 'Debian | Configure the Amazon Corretto repository'
when: java_distribution == 'corretto'
become: true
block:
- name: 'Debian | Ensure the dependencies are installed'
ansible.builtin.apt:
name:
- 'apt-transport-https'
- 'ca-certificates'
- 'gnupg'
update_cache: true
state: 'present'
when: not ansible_check_mode

- name: 'Debian | Add the Amazon Corretto repository GPG key'
ansible.builtin.apt_key:
url: '{{ java_corretto_repository_gpgkey_url }}'
keyring: '{{ _java_corretto_local_gpgkey_path }}'
state: 'present'

- name: 'Debian | Add the Amazon Corretto repository'
ansible.builtin.template:
src: 'corretto.list.j2'
dest: '/etc/apt/sources.list.d/corretto.list'
owner: 'root'
group: 'root'
mode: 0644

- name: 'Debian | Install the Java package'
ansible.builtin.apt:
name: '{{ java_package }}'
name: '{{ java_corretto_package_name
if java_distribution == "corretto"
else java_openjdk_package_name }}'
update_cache: true
state: 'present'
when: not ansible_check_mode
Expand Down
24 changes: 23 additions & 1 deletion tasks/install-RedHat.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,28 @@
---
- name: 'RedHat | Configure the Amazon Corretto repository'
when:
- java_distribution == 'corretto' and
ansible_distribution != 'Amazon'
become: true
block:
- name: 'RedHat | Ensure the dependencies are installed'
ansible.builtin.package:
name: 'yum-utils'
state: 'present'

- name: 'RedHat | Add the Amazon Corretto repository'
ansible.builtin.template:
src: 'corretto.repo.j2'
dest: '/etc/yum.repos.d/corretto.repo'
owner: 'root'
group: 'root'
mode: 0644

- name: 'RedHat | Install the Java package'
ansible.builtin.package:
name: '{{ java_package }}'
name: "{{ java_corretto_package_name
if java_distribution == 'corretto' or
ansible_distribution == 'Amazon'
else java_openjdk_package_name }}"
state: 'present'
become: true
3 changes: 3 additions & 0 deletions templates/corretto.list.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{{ ansible_managed | comment }}

deb [signed-by={{ _java_corretto_local_gpgkey_path }}] {{ java_corretto_repository_mirror_url }} stable main
8 changes: 8 additions & 0 deletions templates/corretto.repo.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{{ ansible_managed | comment }}

[AmazonCorretto]
name=Amazon Corretto
baseurl={{ java_corretto_repository_mirror_url }}/$basearch
enabled=1
gpgkey={{ java_corretto_repository_gpgkey_url }}
gpgcheck=1
2 changes: 1 addition & 1 deletion vars/Amazon.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
_default_java_package: "{{ (ansible_distribution_major_version == '2018') | ternary('java-1.8.0-openjdk', 'java-17-amazon-corretto') }}"
_java_corretto_package_name: 'java-17-amazon-corretto-devel'
7 changes: 6 additions & 1 deletion vars/Debian.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
---
_default_java_package: "{{ (ansible_distribution_major_version == '10') | ternary('openjdk-11-jre', 'openjdk-17-jre') }}"
_java_corretto_repository_mirror_url: 'https://apt.corretto.aws'
_java_corretto_repository_gpgkey_url: '{{ _java_corretto_repository_mirror_url }}/corretto.key'
_java_corretto_local_gpgkey_path: '/usr/share/keyrings/corretto-archive-keyring.gpg'
_java_corretto_package_name: 'java-17-amazon-corretto-jdk'

_java_openjdk_package_name: "{{ (ansible_distribution_major_version == '10') | ternary('openjdk-11-jre', 'openjdk-17-jre') }}"
6 changes: 5 additions & 1 deletion vars/RedHat.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
---
_default_java_package: "{{ (ansible_distribution_major_version == '7') | ternary('java-11-openjdk', 'java-17-openjdk') }}"
_java_corretto_repository_mirror_url: 'https://yum.corretto.aws'
_java_corretto_repository_gpgkey_url: '{{ _java_corretto_repository_mirror_url }}/corretto.key'
_java_corretto_package_name: 'java-17-amazon-corretto-devel'

_java_openjdk_package_name: "{{ (ansible_distribution_major_version == '7') | ternary('java-11-openjdk', 'java-17-openjdk') }}"