Files
dc-deployments-automation/roles/product_common/tasks/amazon-2023.yml

125 lines
5.0 KiB
YAML

---
- name: Add Adoptium repo and install Eclipse Temurin JDK if necessary on Amazon Linux 2023
block:
# There is no amazonlinux/2023 package available from the Adoptium repo; AL2023 docs point to upstream compatiblity
# with Fedora 34, 35, and 36, so we use the latest of those for the Temurin package for now
- name: Add Adoptium yum repository
ansible.builtin.yum_repository:
name: Adoptium
file: adoptium
description: Adoptium Repo
baseurl:
- "https://packages.adoptium.net/artifactory/rpm/fedora/36/{{ ansible_architecture }}"
- "{{ atl_adoptium_alternate_url is defined | ternary(atl_adoptium_alternate_url, '') }}"
gpgkey:
- https://packages.adoptium.net/artifactory/api/gpg/key/public
- "{{ atl_adoptium_gpgkey_alternate_url is defined | ternary(atl_adoptium_gpgkey_alternate_url, '') }}"
gpgcheck: yes
state: present
tags:
- molecule-idempotence-notest
# test if jdk_download_completed lock direcory exists
- name: Check if jdk_download_completed lock directory exists
ansible.builtin.stat:
path: "{{ atl_product_home_shared_download_dir }}/temurin-{{ java_major_version }}-jdk_download_completed"
register: jdk_download_completed_lock
- name: create jdk_downloading lock directory
ansible.builtin.file:
path: "{{ atl_product_home_shared_download_dir }}/temurin-{{ java_major_version }}-jdk_downloading"
state: directory
register: jdk_downloading_lock
when:
- jdk_download_completed_lock
- not jdk_download_completed_lock.stat.exists
# handle the jdk download on only 1 node
- block:
- name: Try 5 times to download Eclipse Temurin JDK with dnf
ansible.builtin.dnf:
name: "temurin-{{ java_major_version }}-jdk"
state: present
download_dir: "{{ atl_product_home_shared_download_dir }}"
download_only: true
update_cache: true
register: jdk_downloaded
retries: 5
delay: 10
until: jdk_downloaded is succeeded
- name: Create jdk_download_completed lock directory if download was successful
ansible.builtin.file:
path: "{{ atl_product_home_shared_download_dir }}/temurin-{{ java_major_version }}-jdk_download_completed"
state: directory
when: jdk_downloaded.changed
- name: Remove jdk_downloading lock directory on success or fail
ansible.builtin.file:
path: "{{ atl_product_home_shared_download_dir }}/temurin-{{ java_major_version }}-jdk_downloading"
state: absent
# this when applies to the whole block - only do this block on the one node that created the downloading lock
when:
- jdk_downloading_lock
- jdk_downloading_lock.changed
# all nodes can wait here in race condition briefly for dl to complete and the downloaded_lock to exist
- name: wait and test 5 times for jdk_download_completed lock to exist
ansible.builtin.wait_for:
path: "{{ atl_product_home_shared_download_dir }}/temurin-{{ java_major_version }}-jdk_download_completed"
state: present
timeout: 10
ignore_errors: true
register: jdk_download_completed_lock
retries: 5
# as long as we have a valid rpm filepath do the copy/install block
- block:
- name: Find a file called temurin* in atl_product_home_shared_download_dir
ansible.builtin.find:
paths: "{{ atl_product_home_shared_download_dir }}"
patterns: "temurin-{{ java_major_version }}-*.rpm"
file_type: file
recurse: no
size: 1
register: temurin_rpm_file
- name: set facts for the path and the basename of the temurin file
ansible.builtin.set_fact:
temurin_file_path: "{{ item.path }}"
temurin_file_name: "{{ item.path | basename }}"
loop: "{{ temurin_rpm_file.files | flatten }}"
- name: Install JDK from cache copy of the rpm file - keepcache
ansible.builtin.command:
cmd: "dnf -y install {{ temurin_file_path }} --setopt=installonly_limit=3 --setopt=keepcache=1"
register: dnf_installed
when:
- jdk_download_completed_lock.state is defined
- jdk_download_completed_lock.state == "directory"
- name: Ensure Eclipse Temurin JDK is present (get from internet if cache install fails or is unavailable)
ansible.builtin.command:
cmd: "dnf -y install temurin-{{ java_major_version }}-jdk --setopt=installonly_limit=3 --setopt=keepcache=1"
- name: Ensure common JDK symlink exists
community.general.alternatives:
link: "/usr/lib/jvm/java"
name: "java_sdk"
path: "/usr/lib/jvm/temurin-{{ java_major_version }}-jdk"
priority: 99
when: atl_use_system_jdk | bool
tags:
- runtime_pkg
- name: Install other base packages on Amazon Linux 2023
ansible.builtin.dnf:
name:
- dejavu-fonts-all # Required by the installer