Skip to content

Commit

Permalink
improv: merge OS-specific variables into the vars/main.yml file (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
antmelekhin authored Aug 10, 2024
1 parent 851beaa commit d05d72f
Show file tree
Hide file tree
Showing 11 changed files with 61 additions and 53 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ Requirements
Role Variables
--------------

All variables which can be overridden are stored in `defaults/main.yml` file as well as in `meta/argument_specs.yml`.
Similarly, descriptions and defaults for preset variables can be found in the `vars/` directory.
All variables that can be overridden are stored in the [defaults/main.yml](https://github.com/antmelekhin/ansible-role-java/blob/main/defaults/main.yml) file.
Please refer to the [meta/argument_specs.yml](https://github.com/antmelekhin/ansible-role-java/blob/main/meta/argument_specs.yml) file for a description of the available variables.
Similarly, descriptions and defaults for preset variables can be found in the [vars/main.yml](https://github.com/antmelekhin/ansible-role-java/blob/main/vars/main.yml) file.

Dependencies
------------
Expand Down
10 changes: 5 additions & 5 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
java_distribution: 'openjdk'

# Install the OpenJDK package
# java_openjdk_package_name: ''
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_gpgkey_url: ''
# java_corretto_repository: ''
# java_corretto_package_name: ''
java_corretto_repository_mirror_url: '{{ __java_corretto_repository_mirror_url }}'
java_corretto_repository_gpgkey_url: '{{ __java_corretto_repository_gpgkey_url }}'
java_corretto_repository: '{{ __java_corretto_repository }}'
java_corretto_package_name: '{{ __java_corretto_package_name }}'

# Configure the JAVA_HOME environment variable
java_home: ''
5 changes: 5 additions & 0 deletions meta/argument_specs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,27 @@ argument_specs:
java_openjdk_package_name:
type: 'str'
description: 'The OpenJDK package name.'
default: '{{ __java_openjdk_package_name }}'
java_corretto_repository_mirror_url:
type: 'str'
description:
- 'The Amazon Corretto repository mirror.'
- 'By default, the role uses https://apt.corretto.aws for Debian-based distributions and https://yum.corretto.aws for RedHat-based distributions.'
default: '{{ __java_corretto_repository_mirror_url }}'
java_corretto_repository_gpgkey_url:
type: 'str'
description:
- 'Specify where to fetch the Amazon Corretto GPG key file from.'
- 'By default, the role uses the official Amazon Corretto GPG key.'
default: '{{ __java_corretto_repository_gpgkey_url }}'
java_corretto_repository:
type: 'str'
description: 'Specify the Amazon Corretto repository.'
default: '{{ __java_corretto_repository }}'
java_corretto_package_name:
type: 'str'
description: 'The Amazon Corretto package name.'
default: '{{ __java_corretto_package_name }}'
java_home:
type: 'str'
description: 'The JAVA_HOME environment variable is used to specify the location of the Java executable files.'
10 changes: 5 additions & 5 deletions tasks/install-Debian.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

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

Expand All @@ -28,11 +28,11 @@
group: 'root'
mode: 0644

- name: "Debian | Install the {{ (java_distribution == 'corretto') | ternary('Amazon Corretto', 'OpenJDK') }} package"
- name: 'Debian | Install the {{ __java_package_distribution }} package'
ansible.builtin.apt:
name: "{{ java_corretto_package_name | default(__java_corretto_package_name)
if java_distribution == 'corretto'
else java_openjdk_package_name | default(__java_openjdk_package_name) }}"
name: '{{ java_corretto_package_name
if java_distribution == "corretto"
else java_openjdk_package_name }}'
update_cache: true
state: 'present'
ignore_errors: '{{ ansible_check_mode }}'
Expand Down
9 changes: 5 additions & 4 deletions tasks/install-RedHat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@
group: 'root'
mode: 0644

- name: "RedHat | Install the {{ (java_distribution == 'corretto') | ternary('Amazon Corretto', 'OpenJDK') }} package"
- name: 'RedHat | Install the {{ __java_package_distribution }} package'
ansible.builtin.package:
name: "{{ java_corretto_package_name | default(__java_corretto_package_name)
if java_distribution == 'corretto' or ansible_distribution == 'Amazon'
else java_openjdk_package_name | default(__java_openjdk_package_name) }}"
name: "{{ java_corretto_package_name
if java_distribution == 'corretto' or
ansible_distribution == 'Amazon'
else java_openjdk_package_name }}"
state: 'present'
become: true
3 changes: 0 additions & 3 deletions tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
---
- name: 'Load the Java OS-specific variables'
ansible.builtin.include_vars: '{{ ansible_os_family }}.yml'

- name: 'Install the Java package'
ansible.builtin.include_tasks: 'install-{{ ansible_os_family }}.yml'

Expand Down
2 changes: 1 addition & 1 deletion templates/corretto.list.j2
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{{ ansible_managed | comment }}

deb [signed-by={{ __java_corretto_repository_gpgkey_keyring }}] {{ java_corretto_repository | default(__java_corretto_repository) }}
deb [signed-by={{ __java_corretto_repository_gpgkey_keyring }}] {{ java_corretto_repository }}
4 changes: 2 additions & 2 deletions templates/corretto.repo.j2
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[AmazonCorretto]
name=Amazon Corretto
baseurl={{ java_corretto_repository | default(__java_corretto_repository) }}
baseurl={{ java_corretto_repository }}
enabled=1
gpgcheck=1
gpgkey={{ java_corretto_repository_gpgkey_url | default(__java_corretto_repository_gpgkey_url) }}
gpgkey={{ java_corretto_repository_gpgkey_url }}
16 changes: 0 additions & 16 deletions vars/Debian.yml

This file was deleted.

15 changes: 0 additions & 15 deletions vars/RedHat.yml

This file was deleted.

35 changes: 35 additions & 0 deletions vars/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
# A variable that is used to name the installation task
__java_package_distribution: "{{ (java_distribution == 'corretto') | ternary('Amazon Corretto', 'OpenJDK') }}"

# Default OpenJDK package
__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') }}"

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

# Default Amazon Corretto mirror
__java_corretto_repository_mirror_url_dict:
Debian: 'https://apt.corretto.aws'
RedHat: 'https://yum.corretto.aws'

__java_corretto_repository_mirror_url: '{{ __java_corretto_repository_mirror_url_dict[ansible_os_family] }}'

# Default Amazon Corretto GPG key
__java_corretto_repository_gpgkey_url: '{{ __java_corretto_repository_mirror_url }}/corretto.key'
__java_corretto_repository_gpgkey_keyring: '/usr/share/keyrings/corretto-archive-keyring.gpg'

# Default Amazon Corretto repository
__java_corretto_repository_dict:
Debian: '{{ __java_corretto_repository_mirror_url }} stable main'
RedHat: '{{ __java_corretto_repository_mirror_url }}/$basearch'

__java_corretto_repository: '{{ __java_corretto_repository_dict[ansible_os_family] }}'

# Default Amazon Corretto package
__java_corretto_package_name_dict:
Debian: 'java-17-amazon-corretto-jdk'
RedHat: 'java-17-amazon-corretto-devel'

__java_corretto_package_name: '{{ __java_corretto_package_name_dict[ansible_os_family] }}'

0 comments on commit d05d72f

Please sign in to comment.