summaryrefslogtreecommitdiff
path: root/roles/raspios/image/tasks/fetch.yml
blob: c95f1deaf203e723dfbcd700744cc3f2f70c9141 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
---
- name: Create download directory
  file:
    dest: "{{ raspios_download_dir }}"
    state: directory

- name: download the raspios image
  block:
  - name: download sha256sum
    get_url:
      url: "{{ raspios_download_base_url }}/{{ raspios_download_image_base_name }}.zip.sha256"
      dest: "{{ raspios_download_dir }}/{{ raspios_download_image_base_name }}.zip.sha256"

  - name: download signature
    get_url:
      url: "{{ raspios_download_base_url }}/{{ raspios_download_image_base_name }}.zip.sig"
      dest: "{{ raspios_download_dir }}/{{ raspios_download_image_base_name }}.zip.sig"

  - name: extract SHA256 hash of the image archive
    command: grep '{{ raspios_download_image_base_name }}.zip' "{{ raspios_download_dir }}/{{ raspios_download_image_base_name }}.zip.sha256"
    changed_when: False
    register: sha256

  - name: download image
    get_url:
      url: "{{ raspios_download_base_url }}/{{ raspios_download_image_base_name }}.zip"
      dest: "{{ raspios_download_dir }}/{{ raspios_download_image_base_name }}.zip"
      checksum: sha256:{{ sha256.stdout.split(' ') | first }}

  - name: check OpenPGP signature
    command: >-
      gpgv --keyring "{{ global_files_dir }}/common/keyrings/raspios.gpg"
          "{{ raspios_download_dir }}/{{ raspios_download_image_base_name }}.zip.sig" "{{ raspios_download_dir }}/{{ raspios_download_image_base_name }}.zip"
    changed_when: False
    register: raspios_image_gpg_result

  - debug:
      var: raspios_image_gpg_result.stderr_lines

  rescue:
  - name: delete downloaded artifacts
    loop:
      - "{{ raspios_download_dir }}/{{ raspios_download_image_base_name }}.zip.sha256"
      - "{{ raspios_download_dir }}/{{ raspios_download_image_base_name }}.zip.sig"
      - "{{ raspios_download_dir }}/{{ raspios_download_image_base_name }}.zip"
    file:
      path: "{{ item }}"
      state: absent

  - name: the download has failed...
    fail:
      msg: Something borked