From b4e6a203893b30e18bc647dc8961820c12c4c32b Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Fri, 2 Sep 2022 20:48:59 +0200 Subject: ubuntu/installer: improved handling of latest image --- .../fetch/tasks/determine-latest-version.yml | 10 ++++++ .../installer/ubuntu/fetch/tasks/fetch-latest.yml | 13 ------- .../installer/ubuntu/fetch/tasks/fetch-version.yml | 41 ---------------------- .../installer/ubuntu/fetch/tasks/find-location.yml | 41 ++++++++++++++++++++++ roles/installer/ubuntu/fetch/tasks/main.yml | 6 +++- roles/installer/ubuntu/fetch/vars/main.yml | 2 +- 6 files changed, 57 insertions(+), 56 deletions(-) create mode 100644 roles/installer/ubuntu/fetch/tasks/determine-latest-version.yml delete mode 100644 roles/installer/ubuntu/fetch/tasks/fetch-latest.yml delete mode 100644 roles/installer/ubuntu/fetch/tasks/fetch-version.yml create mode 100644 roles/installer/ubuntu/fetch/tasks/find-location.yml (limited to 'roles/installer/ubuntu/fetch') diff --git a/roles/installer/ubuntu/fetch/tasks/determine-latest-version.yml b/roles/installer/ubuntu/fetch/tasks/determine-latest-version.yml new file mode 100644 index 00000000..0b8cf3f9 --- /dev/null +++ b/roles/installer/ubuntu/fetch/tasks/determine-latest-version.yml @@ -0,0 +1,10 @@ +--- +- name: downloading SHA256SUMS file for latest release + uri: + url: "https://releases.ubuntu.com/{{ ubuntu_installer_codename }}/SHA256SUMS" + return_content: yes + register: ubuntu_installer_latest_sha256sums + +- name: set version to the latest release + set_fact: + ubuntu_installer_version: "{{ ubuntu_installer_latest_sha256sums.content | regex_search('ubuntu-([0-9.]+)-'+ubuntu_installer_variant+'-'+ubuntu_installer_arch+'.iso', '\\1') | first }}" diff --git a/roles/installer/ubuntu/fetch/tasks/fetch-latest.yml b/roles/installer/ubuntu/fetch/tasks/fetch-latest.yml deleted file mode 100644 index 9baa6d97..00000000 --- a/roles/installer/ubuntu/fetch/tasks/fetch-latest.yml +++ /dev/null @@ -1,13 +0,0 @@ ---- -- name: downloading SHA256SUMS and signature file for latest release - loop: - - SHA256SUMS - - SHA256SUMS.gpg - get_url: - url: "https://releases.ubuntu.com/{{ ubuntu_installer_codename }}/{{ item }}" - dest: "{{ ubuntu_installer_target_dir }}/{{ item }}" - force: "{{ ubuntu_installer_force_download }}" - -- name: set download url to releases.ubuntu.com - set_fact: - ubuntu_installer_base_url: "https://releases.ubuntu.com/{{ ubuntu_installer_codename }}" diff --git a/roles/installer/ubuntu/fetch/tasks/fetch-version.yml b/roles/installer/ubuntu/fetch/tasks/fetch-version.yml deleted file mode 100644 index 868adc95..00000000 --- a/roles/installer/ubuntu/fetch/tasks/fetch-version.yml +++ /dev/null @@ -1,41 +0,0 @@ ---- -## we need to try old-releases.ubuntu.com first because otherwise it would be impossible to download the initial release -## of any codename release. (i.e. 20.04) -- name: try downloading SHA256SUMS and signature file from old-releases.ubuntu.com - loop: - - SHA256SUMS - - SHA256SUMS.gpg - get_url: - url: "https://old-releases.ubuntu.com/releases/{{ ubuntu_installer_version }}/{{ item }}" - dest: "{{ ubuntu_installer_target_dir }}/{{ item }}" - force: yes - register: ubuntu_installer_old - failed_when: "'status_code' in ubuntu_installer_old and ubuntu_installer_old.status_code not in [200, 404]" - -- when: 404 not in (ubuntu_installer_old.results | selectattr('status_code', 'defined') | map(attribute='status_code') | list) - block: - - name: check if SHA256SUM actually contains the correct iso - command: grep -E '^[0-9a-z]{64}\s+\*ubuntu-{{ ubuntu_installer_version }}-{{ ubuntu_installer_variant }}-{{ ubuntu_installer_arch }}.iso$' "{{ ubuntu_installer_target_dir }}/SHA256SUMS" - changed_when: false - failed_when: false - register: ubuntu_installer_old_sha256sum - - - name: set download url to old-releases.ubuntu.com - when: (ubuntu_installer_old_sha256sum.stdout_lines | length) > 0 - set_fact: - ubuntu_installer_base_url: "https://old-releases.ubuntu.com/releases/{{ ubuntu_installer_version }}" - -- when: ubuntu_installer_base_url is not defined - block: - - name: try downloading SHA256SUMS and signature file from releases.ubuntu.com - loop: - - SHA256SUMS - - SHA256SUMS.gpg - get_url: - url: "https://releases.ubuntu.com/{{ ubuntu_installer_version }}/{{ item }}" - dest: "{{ ubuntu_installer_target_dir }}/{{ item }}" - force: yes - - - name: set download url to releases.ubuntu.com - set_fact: - ubuntu_installer_base_url: "https://releases.ubuntu.com/{{ ubuntu_installer_version }}" diff --git a/roles/installer/ubuntu/fetch/tasks/find-location.yml b/roles/installer/ubuntu/fetch/tasks/find-location.yml new file mode 100644 index 00000000..752eebe1 --- /dev/null +++ b/roles/installer/ubuntu/fetch/tasks/find-location.yml @@ -0,0 +1,41 @@ +--- +## we need to try old-releases.ubuntu.com first because otherwise it would be impossible to download the initial release +## of any codename release. (i.e. 20.04) +- name: try downloading SHA256SUMS and signature file from old-releases.ubuntu.com + loop: + - SHA256SUMS + - SHA256SUMS.gpg + get_url: + url: "https://old-releases.ubuntu.com/releases/{{ ubuntu_installer_codename }}/{{ item }}" + dest: "{{ ubuntu_installer_target_dir }}/{{ item }}" + force: yes + register: ubuntu_installer_old + failed_when: "'status_code' in ubuntu_installer_old and ubuntu_installer_old.status_code not in [200, 404]" + +- when: 404 not in (ubuntu_installer_old.results | selectattr('status_code', 'defined') | map(attribute='status_code') | list) + block: + - name: check if SHA256SUM actually contains the correct iso + command: grep -E '^[0-9a-z]{64}\s+\*ubuntu-{{ ubuntu_installer_version }}-{{ ubuntu_installer_variant }}-{{ ubuntu_installer_arch }}.iso$' "{{ ubuntu_installer_target_dir }}/SHA256SUMS" + changed_when: false + failed_when: false + register: ubuntu_installer_old_sha256sum + + - name: set download url to old-releases.ubuntu.com + when: (ubuntu_installer_old_sha256sum.stdout_lines | length) > 0 + set_fact: + ubuntu_installer_base_url: "https://old-releases.ubuntu.com/releases/{{ ubuntu_installer_codename }}" + +- when: ubuntu_installer_base_url is not defined + block: + - name: try downloading SHA256SUMS and signature file from releases.ubuntu.com + loop: + - SHA256SUMS + - SHA256SUMS.gpg + get_url: + url: "https://releases.ubuntu.com/{{ ubuntu_installer_codename }}/{{ item }}" + dest: "{{ ubuntu_installer_target_dir }}/{{ item }}" + force: yes + + - name: set download url to releases.ubuntu.com + set_fact: + ubuntu_installer_base_url: "https://releases.ubuntu.com/{{ ubuntu_installer_codename }}" diff --git a/roles/installer/ubuntu/fetch/tasks/main.yml b/roles/installer/ubuntu/fetch/tasks/main.yml index 618cfd22..a4f7f720 100644 --- a/roles/installer/ubuntu/fetch/tasks/main.yml +++ b/roles/installer/ubuntu/fetch/tasks/main.yml @@ -1,10 +1,14 @@ --- +- when: ubuntu_installer_version is undefined + include_tasks: determine-latest-version.yml + - name: prepare directories for installer files file: name: "{{ ubuntu_installer_target_dir }}" state: directory -- include_tasks: "fetch-{{ (ubuntu_installer_version is defined) | ternary('version', 'latest') }}.yml" +- name: find download location for release version + import_tasks: find-location.yml - name: verfiy signature of SHA256SUMS file command: >- diff --git a/roles/installer/ubuntu/fetch/vars/main.yml b/roles/installer/ubuntu/fetch/vars/main.yml index caf1fa67..29ca94a6 100644 --- a/roles/installer/ubuntu/fetch/vars/main.yml +++ b/roles/installer/ubuntu/fetch/vars/main.yml @@ -1,2 +1,2 @@ --- -ubuntu_installer_target_dir: "{{ installer_base_path }}/{{ ubuntu_installer_codename }}/{{ ubuntu_installer_version | default('latest') }}-{{ ubuntu_installer_variant }}" +ubuntu_installer_target_dir: "{{ installer_base_path }}/{{ ubuntu_installer_codename }}/{{ ubuntu_installer_version }}-{{ ubuntu_installer_variant }}" -- cgit v1.2.3