From fae39fcd5ae1358aa87a0b9887ca51425539e106 Mon Sep 17 00:00:00 2001 From: Anton Melekhin <44847512+antmelekhin@users.noreply.github.com> Date: Sat, 27 Jul 2024 16:58:30 +0300 Subject: [PATCH] fix: split `vars/main.yml` file by distribution (#7) --- tasks/install-Debian.yml | 9 ++++----- tasks/install-RedHat.yml | 5 ++--- tasks/main.yml | 3 +++ templates/corretto.list.j2 | 2 +- templates/corretto.repo.j2 | 4 ++-- vars/Debian.yml | 16 ++++++++++++++++ vars/RedHat.yml | 15 +++++++++++++++ vars/main.yml | 21 --------------------- 8 files changed, 43 insertions(+), 32 deletions(-) create mode 100644 vars/Debian.yml create mode 100644 vars/RedHat.yml delete mode 100644 vars/main.yml diff --git a/tasks/install-Debian.yml b/tasks/install-Debian.yml index 801f917..0fdbd62 100644 --- a/tasks/install-Debian.yml +++ b/tasks/install-Debian.yml @@ -16,8 +16,8 @@ - name: 'Debian | Add the Amazon Corretto repository GPG key' ansible.builtin.apt_key: - url: '{{ java_corretto_repository_gpgkey_url | default(_java_corretto_debian_repository_gpgkey_url) }}' - keyring: '{{ _java_corretto_debian_repository_gpgkey_keyring }}' + url: '{{ java_corretto_repository_gpgkey_url | default(__java_corretto_repository_gpgkey_url) }}' + keyring: '{{ __java_corretto_repository_gpgkey_keyring }}' state: 'present' - name: 'Debian | Add the Amazon Corretto repository' @@ -30,10 +30,9 @@ - name: "Debian | Install the {{ (java_distribution == 'corretto') | ternary('Amazon Corretto', 'OpenJDK') }} package" ansible.builtin.apt: - name: - "{{ java_corretto_package_name | default(_java_corretto_debian_package_name) + name: "{{ java_corretto_package_name | default(__java_corretto_package_name) if java_distribution == 'corretto' - else java_openjdk_package_name | default(_java_openjdk_debian_package_name) }}" + else java_openjdk_package_name | default(__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 c8abda5..2a6d59d 100644 --- a/tasks/install-RedHat.yml +++ b/tasks/install-RedHat.yml @@ -22,9 +22,8 @@ - name: "RedHat | Install the {{ (java_distribution == 'corretto') | ternary('Amazon Corretto', 'OpenJDK') }} package" ansible.builtin.package: - name: - "{{ java_corretto_package_name | default(_java_corretto_redhat_package_name) + 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_redhat_package_name) }}" + else java_openjdk_package_name | default(__java_openjdk_package_name) }}" state: 'present' become: true diff --git a/tasks/main.yml b/tasks/main.yml index 1c11468..24dc853 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,4 +1,7 @@ --- +- 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 15189ff..68a550d 100644 --- a/templates/corretto.list.j2 +++ b/templates/corretto.list.j2 @@ -1,3 +1,3 @@ {{ ansible_managed | comment }} -deb [signed-by={{ _java_corretto_debian_repository_gpgkey_keyring }}] {{ java_corretto_repository | default(_java_corretto_debian_repository) }} +deb [signed-by={{ __java_corretto_repository_gpgkey_keyring }}] {{ java_corretto_repository | default(__java_corretto_repository) }} diff --git a/templates/corretto.repo.j2 b/templates/corretto.repo.j2 index 5a092cc..4382936 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_redhat_repository) }} +baseurl={{ java_corretto_repository | default(__java_corretto_repository) }} enabled=1 gpgcheck=1 -gpgkey={{ _java_corretto_redhat_repository_gpgkey_url }} +gpgkey={{ java_corretto_repository_gpgkey_url | default(__java_corretto_repository_gpgkey_url) }} diff --git a/vars/Debian.yml b/vars/Debian.yml new file mode 100644 index 0000000..fdb2599 --- /dev/null +++ b/vars/Debian.yml @@ -0,0 +1,16 @@ +--- +# 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 new file mode 100644 index 0000000..849cadc --- /dev/null +++ b/vars/RedHat.yml @@ -0,0 +1,15 @@ +--- +# 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 deleted file mode 100644 index e032387..0000000 --- a/vars/main.yml +++ /dev/null @@ -1,21 +0,0 @@ ---- -# Default OpenJDK packages -_java_openjdk_debian_package_name: "{{ (ansible_distribution_major_version == '10') | ternary('openjdk-11-jre', 'openjdk-17-jre') }}" -_java_openjdk_redhat_package_name: "{{ (ansible_distribution_major_version == '7') | ternary('java-11-openjdk', 'java-17-openjdk') }}" - -# Default Amazon Corretto mirrors -_java_corretto_debian_repository_mirror_url: 'https://apt.corretto.aws' -_java_corretto_redhat_repository_mirror_url: 'https://yum.corretto.aws' - -# Default Amazon Corretto GPG key -_java_corretto_debian_repository_gpgkey_url: '{{ _java_corretto_debian_repository_mirror_url }}/corretto.key' -_java_corretto_debian_repository_gpgkey_keyring: '/usr/share/keyrings/corretto-archive-keyring.gpg' -_java_corretto_redhat_repository_gpgkey_url: '{{ _java_corretto_redhat_repository_mirror_url }}/corretto.key' - -# Default Amazon Corretto repositories -_java_corretto_debian_repository: '{{ _java_corretto_debian_repository_mirror_url }} stable main' -_java_corretto_redhat_repository: '{{ _java_corretto_redhat_repository_mirror_url }}/$basearch' - -# Default Amazon Corretto packages -_java_corretto_debian_package_name: 'java-17-amazon-corretto-jdk' -_java_corretto_redhat_package_name: 'java-17-amazon-corretto-devel'