|
4 | 4 |
|
5 | 5 |
|
6 | 6 | - name: Make code directories available |
7 | | - ansible.builtin.file: |
| 7 | + file: |
8 | 8 | path: "{{ item }}" |
9 | 9 | state: directory |
10 | 10 | mode: "0755" |
|
13 | 13 | - "{{ code_serve_path }}" |
14 | 14 |
|
15 | 15 | - name: Copy static assets |
16 | | - ansible.builtin.copy: |
| 16 | + copy: |
17 | 17 | src: static/ |
18 | 18 | dest: "{{ code_data_root_static }}" |
19 | 19 |
|
| 20 | +- name: Ensure code_apk_release_name is set (autodetect latest armv8a APK if empty) |
| 21 | + when: code_apk_release_name is undefined |
| 22 | + block: |
| 23 | + |
| 24 | + - name: Fetch APK index page from {{ code_download_url }}/ |
| 25 | + uri: |
| 26 | + url: "{{ code_download_url }}/" |
| 27 | + return_content: true |
| 28 | + register: apk_index |
| 29 | + failed_when: apk_index.status != 200 and apk_index.status != 403 |
| 30 | + |
| 31 | + - name: Mark 'code' role as blocked by CDN |
| 32 | + set_fact: |
| 33 | + code_blocked_by_cdn: true |
| 34 | + when: apk_index.status == 403 |
| 35 | + |
| 36 | + - name: Warn about 403 APK index |
| 37 | + fail: |
| 38 | + msg: | |
| 39 | + The 'code' role could not access: {{ code_download_url }}/ (HTTP 403). CDN is likely blocking datacenter IPs. |
| 40 | +
|
| 41 | + ================ CODE ROLE WARNING ================ |
| 42 | + The 'code' role hit a CDN 403 (APK index query blocked). |
| 43 | +
|
| 44 | + HTTP status: 403 |
| 45 | + This likely means the APK store is behind some CDN and |
| 46 | + blocking datacenter IP ranges, so non-interactive curl/Ansible |
| 47 | + requests get a 403 "Just a moment..." page. |
| 48 | +
|
| 49 | + GitHub issues/PRs related: |
| 50 | + - https://github.com/iiab/iiab/issues/4174 |
| 51 | + - https://github.com/iiab/iiab/pull/4176 |
| 52 | +
|
| 53 | + Continuing IIAB without CodeOnTheGo APK content... |
| 54 | + =================================================== |
| 55 | + when: code_blocked_by_cdn is defined |
| 56 | + ignore_errors: yes |
| 57 | + |
| 58 | + - name: Warn about APK index 403 blocking |
| 59 | + pause: |
| 60 | + seconds: 20 |
| 61 | + when: code_blocked_by_cdn is defined |
| 62 | + |
| 63 | + - name: Extract latest armv8a APK filename from index |
| 64 | + set_fact: |
| 65 | + code_apk_64bit_filename: >- |
| 66 | + {{ |
| 67 | + apk_index.content |
| 68 | + | regex_findall(code_apk_64bit_pattern) |
| 69 | + | sort |
| 70 | + | last |
| 71 | + }} |
| 72 | + when: code_blocked_by_cdn is undefined |
| 73 | + |
| 74 | + - name: Extract latest armv7a APK filename from index |
| 75 | + set_fact: |
| 76 | + code_apk_32bit_filename: >- |
| 77 | + {{ |
| 78 | + apk_index.content |
| 79 | + | regex_findall(code_apk_32bit_pattern) |
| 80 | + | sort |
| 81 | + | last |
| 82 | + }} |
| 83 | + when: code_blocked_by_cdn is undefined |
| 84 | + |
20 | 85 | - name: Get CodeOnTheGo version number |
21 | | - ansible.builtin.shell: > |
22 | | - curl -s https://appdevforall.org/apk_repo/ | |
23 | | - sed -nE 's/.*CodeOnTheGo-release([0-9.]+)\.apk.*/\1/p' |
24 | | - register: cotg_version_raw |
25 | | - changed_when: false |
| 86 | + set_fact: |
| 87 | + cotg_version: "{{ code_apk_64bit_filename | regex_search('CodeOnTheGo-release([0-9.]+)', '\\1') }}" |
| 88 | + when: code_blocked_by_cdn is undefined |
| 89 | + |
| 90 | +- name: "Show resolved APK release name" |
| 91 | + debug: |
| 92 | + var: cotg_version |
| 93 | + when: code_blocked_by_cdn is undefined |
26 | 94 |
|
27 | 95 | - name: Make index.html file |
28 | | - ansible.builtin.template: |
| 96 | + template: |
29 | 97 | src: "index.html.j2" |
30 | 98 | dest: "{{ code_serve_path }}/index.html" |
31 | 99 | mode: "0644" |
| 100 | + when: code_blocked_by_cdn is undefined |
32 | 101 |
|
33 | 102 | - name: Make content directory |
34 | 103 | file: |
35 | 104 | path: "{{ code_data_root_content }}" |
36 | 105 | state: directory |
37 | 106 | mode: "0755" |
| 107 | + when: code_blocked_by_cdn is undefined |
38 | 108 |
|
39 | 109 | - name: Render localized Markdown content files |
40 | | - ansible.builtin.template: |
| 110 | + template: |
41 | 111 | src: "content/{{ item }}.md.j2" |
42 | 112 | dest: "{{ code_data_root_content }}/{{ item }}.md" |
43 | 113 | mode: "0644" |
44 | 114 | loop: |
45 | 115 | - en |
46 | 116 | - es |
| 117 | + when: code_blocked_by_cdn is undefined |
| 118 | + |
| 119 | +- name: Continue APK install tasks when no 403 blocking |
| 120 | + include_tasks: install_apkfile.yml |
| 121 | + when: code_blocked_by_cdn is undefined |
47 | 122 |
|
48 | | -- include_tasks: install_apkfile.yml |
| 123 | +- name: Setup 'code' nginx conf file |
| 124 | + include_tasks: nginx.yml |
| 125 | + when: code_blocked_by_cdn is undefined |
49 | 126 |
|
50 | 127 |
|
51 | 128 | # RECORD CODE AS INSTALLED |
|
64 | 141 | - name: "Set 'code_installed: True'" |
65 | 142 | set_fact: |
66 | 143 | code_installed: True |
| 144 | + when: code_blocked_by_cdn is undefined |
67 | 145 |
|
68 | 146 | - name: "Add 'code_installed: True' to {{ iiab_state_file }}" |
69 | 147 | lineinfile: |
70 | 148 | path: "{{ iiab_state_file }}" # /etc/iiab/iiab_state.yml |
71 | 149 | regexp: '^code_installed' |
72 | 150 | line: 'code_installed: True' |
| 151 | + when: code_blocked_by_cdn is undefined |
0 commit comments