diff --git a/README.md b/README.md index eb4e531..2b8cae3 100644 --- a/README.md +++ b/README.md @@ -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 ------------ diff --git a/defaults/main.yml b/defaults/main.yml index 75bb716..19df8bc 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -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: '' diff --git a/meta/argument_specs.yml b/meta/argument_specs.yml index 79baa41..b11e2bc 100644 --- a/meta/argument_specs.yml +++ b/meta/argument_specs.yml @@ -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.' diff --git a/tasks/install-Debian.yml b/tasks/install-Debian.yml index 0fdbd62..3e17209 100644 --- a/tasks/install-Debian.yml +++ b/tasks/install-Debian.yml @@ -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' @@ -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 }}' diff --git a/tasks/install-RedHat.yml b/tasks/install-RedHat.yml index 2a6d59d..305fcbc 100644 --- a/tasks/install-RedHat.yml +++ b/tasks/install-RedHat.yml @@ -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 diff --git a/tasks/main.yml b/tasks/main.yml index 24dc853..1c11468 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -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' diff --git a/templates/corretto.list.j2 b/templates/corretto.list.j2 index 68a550d..bf3bdd8 100644 --- a/templates/corretto.list.j2 +++ b/templates/corretto.list.j2 @@ -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 }} diff --git a/templates/corretto.repo.j2 b/templates/corretto.repo.j2 index 4382936..3b20461 100644 --- a/templates/corretto.repo.j2 +++ b/templates/corretto.repo.j2 @@ -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 }} diff --git a/vars/Debian.yml b/vars/Debian.yml deleted file mode 100644 index fdb2599..0000000 --- a/vars/Debian.yml +++ /dev/null @@ -1,16 +0,0 @@ ---- -# Default OpenJDK package -__java_openjdk_package_name: "{{ (ansible_distribution_major_version == '10') | ternary('openjdk-11-jre', 'openjdk-17-jre') }}" - -# Default Amazon Corretto mirror -__java_corretto_repository_mirror_url: 'https://apt.corretto.aws' - -# 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: '{{ __java_corretto_repository_mirror_url }} stable main' - -# Default Amazon Corretto package -__java_corretto_package_name: 'java-17-amazon-corretto-jdk' diff --git a/vars/RedHat.yml b/vars/RedHat.yml deleted file mode 100644 index 849cadc..0000000 --- a/vars/RedHat.yml +++ /dev/null @@ -1,15 +0,0 @@ ---- -# Default OpenJDK package -__java_openjdk_package_name: "{{ (ansible_distribution_major_version == '7') | ternary('java-11-openjdk', 'java-17-openjdk') }}" - -# Default Amazon Corretto mirror -__java_corretto_repository_mirror_url: 'https://yum.corretto.aws' - -# Default Amazon Corretto GPG key -__java_corretto_repository_gpgkey_url: '{{ __java_corretto_repository_mirror_url }}/corretto.key' - -# Default Amazon Corretto repository -__java_corretto_repository: '{{ __java_corretto_repository_mirror_url }}/$basearch' - -# Default Amazon Corretto package -__java_corretto_package_name: 'java-17-amazon-corretto-devel' diff --git a/vars/main.yml b/vars/main.yml new file mode 100644 index 0000000..15fb150 --- /dev/null +++ b/vars/main.yml @@ -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] }}'