Skip to content

Commit

Permalink
feat: add java_type variable (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
antmelekhin authored Oct 6, 2024
1 parent 884ece5 commit 9a8b3cd
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
1 change: 1 addition & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
# Install Java
java_distribution: 'openjdk'
java_type: 'jre'

# Install the OpenJDK package
java_openjdk_package_name: '{{ __java_openjdk_package_name }}'
Expand Down
12 changes: 10 additions & 2 deletions meta/argument_specs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ argument_specs:
description:
- 'An Ansible role to install the Java package.'
- 'This role installs the C(OpenJDK) or C(Amazon Corretto) distribution.'
author:
- 'Melekhin Anton'
author: 'Melekhin Anton'
options:
java_distribution:
type: 'str'
Expand All @@ -15,6 +14,15 @@ argument_specs:
- 'openjdk'
- 'corretto'
default: 'openjdk'
java_type:
type: 'str'
description:
- 'Java package type.'
- 'Amazon Corretto supported only jdk.'
choices:
- 'jre'
- 'jdk'
default: 'jre'
java_openjdk_package_name:
type: 'str'
description: 'The OpenJDK package name.'
Expand Down
22 changes: 19 additions & 3 deletions vars/main.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,27 @@
---
# A variable that is used to name the installation task
__java_package_distribution: "{{ (java_distribution == 'corretto') | ternary('Amazon Corretto', 'OpenJDK') }}"
__java_package_distribution: "{{ (java_distribution == 'corretto' or ansible_distribution == 'Amazon') | ternary('Amazon Corretto', 'OpenJDK') }}"

# Default OpenJDK package
__java_openjdk_major_version_dict:
Debian: "{{ (ansible_distribution_major_version == '10') | ternary('11', '17') }}"
RedHat: "{{ (ansible_distribution_major_version == '7') | ternary('11', '17') }}"

__java_openjdk_major_version: '{{ __java_openjdk_major_version_dict[ansible_os_family] }}'

__java_openjdk_package_name_suffix_dict:
jre:
Debian: 'jre'
RedHat: 'openjdk'
jdk:
Debian: 'jdk'
RedHat: 'openjdk-devel'

__java_openjdk_package_name_suffix: '{{ __java_openjdk_package_name_suffix_dict[java_type][ansible_os_family] }}'

__java_openjdk_package_name_dict:
Debian: "{{ (ansible_distribution_major_version == '10') | ternary('openjdk-11-jdk', 'openjdk-17-jdk') }}"
RedHat: "{{ (ansible_distribution_major_version == '7') | ternary('java-11-openjdk', 'java-17-openjdk') }}"
Debian: 'openjdk-{{ __java_openjdk_major_version }}-{{ __java_openjdk_package_name_suffix }}'
RedHat: 'java-{{ __java_openjdk_major_version }}-{{ __java_openjdk_package_name_suffix }}'

__java_openjdk_package_name: '{{ __java_openjdk_package_name_dict[ansible_os_family] }}'

Expand Down

0 comments on commit 9a8b3cd

Please sign in to comment.