role-amazon-corretto/tasks/install.yml

87 lines
2.5 KiB
YAML

---
- block:
- name: Download Amazon Corretto
become: yes
get_url:
url: "{{ corretto_dl_link }}"
dest: "/tmp/corretto{{ corretto_version }}.tar.gz"
register: corretto_tar
- name: Download Amazon Corretto checksum
become: yes
get_url:
url: "{{ corretto_dl_checksum_link }}"
dest: "/tmp/corretto{{ corretto_version }}.tar.gz.sha256"
- name: Calculate SHA256 checksum of Corretto tar file
become: yes
command: "sha256sum /tmp/corretto{{ corretto_version }}.tar.gz"
register: corretto_checksum
- name: get remote file contents
command: "cat '/tmp/corretto{{ corretto_version }}.tar.gz.sha256'"
register: checksum_from_file
- name: "Set in sha256sum format"
set_fact:
checksum_format: "{{ checksum_from_file.stdout }} /tmp/corretto{{ corretto_version }}.tar.gz"
- name: Compare Corretto checksum with official checksum
assert:
that:
- corretto_checksum.stdout == checksum_format
- name: "Create data directory"
file:
path: "{{ corretto_home }}"
state: directory
owner: "root"
group: "root"
mode: 'u=rwX,g=rX,o='
recurse: true
- name: Unpack golang binary
unarchive:
remote_src: yes
src: "/tmp/corretto{{ corretto_version }}.tar.gz"
dest: "{{ corretto_home }}"
mode: 0755
owner: root
group: root
list_files: true
register: unpacked
- block:
- name: Copy files to new location
copy:
remote_src: True
src: "{{ corretto_home }}/{{ unpacked.files[0] }}"
dest: "{{ corretto_home }}/corretto/"
- name: Remove old files
file:
path: "{{ corretto_home }}/{{ unpacked.files[0] }}"
state: absent
- block:
- name: Load files for Symlink
find:
paths: "{{ corretto_home }}/corretto/bin"
register: symlink_files
- name: Create Java symlink
file:
src: "{{ item.path }}"
dest: "{{ corretto_symlink_dest }}/{{ item.path.split(\"/\") | last }}"
state: link
loop: "{{ symlink_files.files }}"
- block:
- name: Delete all files
file:
path: "/var/lib/corretto/{{ corretto_active_version }}"
state: "absent"
when: corretto_delete_old|bool
when: (not corretto_version_check|bool) or (corretto_active_version != corretto_version)