preseed/install: make disk selection work with udev device paths
[noc.git] / ansible / roles / openwrt / image / tasks / fetch.yml
1 ---
2 - name: Create download directory
3   file:
4     dest: "{{ openwrt_download_dir }}"
5     state: directory
6
7 - block:
8     - name: Generate OpenWrt download URLs
9       set_fact:
10         openwrt_url:
11           https://downloads.openwrt.org/releases/{{ openwrt_release }}/targets/{{ openwrt_arch | mandatory }}/{{ openwrt_target }}
12
13     - name: Download sha256sums
14       get_url:
15         url: "{{ openwrt_url }}/sha256sums"
16         dest: "{{ openwrt_download_dir }}/{{ openwrt_tarball_basename }}.sha256"
17
18     - name: Download sha256sums.asc
19       get_url:
20         url: "{{ openwrt_url }}/sha256sums.asc"
21         dest: "{{ openwrt_download_dir }}/{{ openwrt_tarball_basename }}.sha256.asc"
22
23     - name: Check OpenPGP signature
24       command: >-
25         gpg2 --no-options --no-default-keyring --secret-keyring /dev/null
26              --verify --keyring "{{ role_path }}/openwrt-keyring.gpg"
27              --trust-model always
28              "{{ openwrt_download_dir }}/{{ openwrt_tarball_basename }}.sha256.asc"
29       changed_when: False
30
31     - name: Extract SHA256 hash of the imagebuilder archive
32       command: grep '{{ openwrt_tarball_name }}' "{{ openwrt_download_dir }}/{{ openwrt_tarball_basename }}.sha256"
33       register: sha256
34       changed_when: False
35
36     - name: Download imagebuilder
37       get_url:
38         url: "{{ openwrt_url }}/{{ openwrt_tarball_name }}"
39         dest: "{{ openwrt_download_dir }}/{{ openwrt_tarball_name }}"
40         checksum: sha256:{{ sha256.stdout.split(' ') | first }}
41
42   rescue:
43     - name: Delete downloaded artifacts
44       file:
45         path: "{{ item }}"
46         state: absent
47       with_items:
48         - "{{ openwrt_download_dir }}/{{ openwrt_tarball_basename }}.sha256"
49         - "{{ openwrt_download_dir }}/{{ openwrt_tarball_basename }}.sha256.asc"
50         - "{{ openwrt_download_dir }}/{{ openwrt_tarball_name }}"
51     - fail:
52         msg: Something borked