|
| 1 | +--- |
| 2 | +- hosts: localhost |
| 3 | + connection: local |
| 4 | + gather_facts: no |
| 5 | + tasks: |
| 6 | + - name: Set facts for whether enough variables are set |
| 7 | + tags: all, compare, scoreboard, awards, fetch |
| 8 | + ansible.builtin.set_fact: |
| 9 | + cds_available: "{{ cds_url is defined and cds_url_api_suffix is defined and cds_username is defined and cds_password is defined }}" |
| 10 | + other_available: "{{ other_url is defined and other_url_api_suffix is defined and other_username is defined and other_password is defined }}" |
| 11 | + |
| 12 | + # Do this to prevent the dreaded issues with basic auth. Tedious but it works |
| 13 | + - name: Set DOMjudge basic auth fact |
| 14 | + tags: all, compare, scoreboard, awards, fetch |
| 15 | + ansible.builtin.set_fact: |
| 16 | + dj_basic_auth: "Basic {{ (dj_username+':'+dj_password) | b64encode }}" |
| 17 | + |
| 18 | + - name: Set CDS basic auth fact |
| 19 | + tags: all, compare, scoreboard, awards |
| 20 | + ansible.builtin.set_fact: |
| 21 | + cds_basic_auth: "Basic {{ (cds_username+':'+cds_password) | b64encode }}" |
| 22 | + when: cds_available |
| 23 | + |
| 24 | + - name: Set other basic auth fact |
| 25 | + tags: all, compare, scoreboard, awards |
| 26 | + ansible.builtin.set_fact: |
| 27 | + other_basic_auth: "Basic {{ (other_username+':'+other_password) | b64encode }}" |
| 28 | + when: other_available |
| 29 | + |
| 30 | + |
| 31 | + - name: Attempt login into DOMjudge |
| 32 | + tags: all, fetch, results.tsv |
| 33 | + block: |
| 34 | + - name: Fetch CSRF from login page |
| 35 | + ansible.builtin.uri: |
| 36 | + method: GET |
| 37 | + return_content: yes |
| 38 | + url: "{{ dj_url }}/login" |
| 39 | + register: DOMjudge_login_output |
| 40 | + |
| 41 | + - name: Extract CSRF input field |
| 42 | + ansible.builtin.set_fact: |
| 43 | + DOMjudge_csrf_field: "{{ DOMjudge_login_output.content | regex_search('<input[^>]+?_csrf_token[^>]+?>') | regex_search('[^\"]{30,}') }}" |
| 44 | + |
| 45 | + - name: Login into DOMjudge and retrieve cookie |
| 46 | + ansible.builtin.uri: |
| 47 | + method: POST |
| 48 | + body_format: form-urlencoded |
| 49 | + url: "{{ dj_url }}/login" |
| 50 | + status_code: 302 |
| 51 | + headers: |
| 52 | + cookie: "{{ DOMjudge_login_output.cookies_string }}" |
| 53 | + body: |
| 54 | + _username: "{{ dj_username }}" |
| 55 | + _password: "{{ dj_password }}" |
| 56 | + _csrf_token: "{{ DOMjudge_csrf_field }}" |
| 57 | + register: login_response |
| 58 | + |
| 59 | + - name: Test succesfull login by going to a restricted page |
| 60 | + ansible.builtin.uri: |
| 61 | + url: "{{ dj_url }}/jury" |
| 62 | + method: GET |
| 63 | + headers: |
| 64 | + cookie: "{{ login_response.set_cookie }}" |
| 65 | + |
| 66 | + |
| 67 | + - name: Download results.tsv |
| 68 | + tags: all, results.tsv |
| 69 | + ansible.builtin.uri: |
| 70 | + url: "{{ dj_url }}/jury/import-export/export/results.tsv" |
| 71 | + return_content: yes |
| 72 | + method: GET |
| 73 | + creates: "{{ repo }}/results.tsv" |
| 74 | + dest: "{{ repo }}/results.tsv" |
| 75 | + headers: |
| 76 | + cookie: "{{ login_response.set_cookie }}" |
| 77 | + |
| 78 | + - name: Compare scoreboard.json |
| 79 | + tags: all, compare, scoreboard |
| 80 | + block: |
| 81 | + - name: "Fetch scoreboard.json from Dj" |
| 82 | + ansible.builtin.uri: |
| 83 | + url: "{{ dj_url }}/{{ dj_url_api_suffix }}/contests/{{ contest }}/scoreboard" |
| 84 | + dest: "/tmp/scoreboard.dj.json" |
| 85 | + return_content: yes |
| 86 | + force: yes |
| 87 | + headers: |
| 88 | + Authorization: "{{ dj_basic_auth }}" |
| 89 | + register: dj_scoreboard |
| 90 | + |
| 91 | + - name: "Fetch scoreboard.json from other" |
| 92 | + ansible.builtin.uri: |
| 93 | + url: "{{ other_url }}/{{ other_url_api_suffix }}/contests/{{ contest }}/scoreboard" |
| 94 | + dest: "/tmp/scoreboard.other.json" |
| 95 | + return_content: yes |
| 96 | + force: yes |
| 97 | + headers: |
| 98 | + Authorization: "{{ other_basic_auth }}" |
| 99 | + register: other_scoreboard |
| 100 | + when: other_available |
| 101 | + |
| 102 | +# - name: Convert scoreboard to nice json |
| 103 | +# block: |
| 104 | +# - name: Convert DOMjudge scoreboard to nice json |
| 105 | +# ansible.builtin.set_fact: |
| 106 | +# dj_scoreboard_nice: "{{ dj_scoreboard.json | to_nice_json }}" |
| 107 | +# |
| 108 | +# - name: Convert other scoreboard to nice json |
| 109 | +# ansible.builtin.set_fact: |
| 110 | +# other_scoreboard_nice: "{{ other_scoreboard.json | to_nice_json }}" |
| 111 | +# when: other_available |
| 112 | + |
| 113 | + - name: Does Dj == other for scoreboard |
| 114 | + shell: "{{ jd_loc }} /tmp/scoreboard.dj.json /tmp/scoreboard.other.json" |
| 115 | + when: other_available |
| 116 | + |
| 117 | + - name: Compare awards.json |
| 118 | + tags: all, compare, awards |
| 119 | + block: |
| 120 | + - name: Fetch awards.json from Dj |
| 121 | + ansible.builtin.uri: |
| 122 | + url: "{{ dj_url }}/{{ dj_url_api_suffix }}/contests/{{ contest }}/awards/" |
| 123 | + dest: "/tmp/awards.dj.json" |
| 124 | + return_content: yes |
| 125 | + force: yes |
| 126 | + method: GET |
| 127 | + headers: |
| 128 | + Authorization: "{{ dj_basic_auth }}" |
| 129 | + register: dj_awards |
| 130 | + |
| 131 | + - name: Fetch awards.json from cds |
| 132 | + ansible.builtin.uri: |
| 133 | + url: "{{ cds_url }}/{{ cds_url_api_suffix }}/contests/{{ contest }}/awards/" |
| 134 | + dest: "/tmp/awards.cds.json" |
| 135 | + return_content: yes |
| 136 | + force: yes |
| 137 | + method: GET |
| 138 | + headers: |
| 139 | + Authorization: "{{ cds_basic_auth }}" |
| 140 | + register: cds_awards |
| 141 | + when: cds_available |
| 142 | + |
| 143 | +# - name: Convert awards to nice json |
| 144 | +# block: |
| 145 | +# - name: Convert DOMjudge awards to nice json |
| 146 | +# ansible.builtin.set_fact: |
| 147 | +# dj_awards_nice: "{{ dj_awards.json | to_nice_json }}" |
| 148 | +# |
| 149 | +# - name: Convert cds awards to nice json |
| 150 | +# ansible.builtin.set_fact: |
| 151 | +# cds_awards_nice: "{{ cds_awards.json | to_nice_json }}" |
| 152 | +# when: cds_available |
| 153 | + |
| 154 | + - name: Does Dj == CDS for awards |
| 155 | + shell: "{{ jd_loc }} /tmp/awards.dj.json /tmp/awards.cds.json" |
| 156 | + when: cds_available |
| 157 | + |
| 158 | + - name: "Fetch event-feed.ndjson from Dj" |
| 159 | + tags: all, fetch |
| 160 | + ansible.builtin.uri: |
| 161 | + url: "{{ dj_url }}/{{ dj_url_api_suffix }}/contests/{{ contest }}/event-feed?stream=false" |
| 162 | + return_content: yes |
| 163 | + method: GET |
| 164 | + creates: "{{ repo }}/event-feed.ndjson" |
| 165 | + dest: "{{ repo }}/event-feed.ndjson" |
| 166 | + headers: |
| 167 | + Authorization: "{{ dj_basic_auth }}" |
| 168 | + |
| 169 | + - name: "Store final standings (contest.zip)" |
| 170 | + tags: all, fetch |
| 171 | + ansible.builtin.uri: |
| 172 | + url: "{{ dj_url }}/public/scoreboard-data.zip?contest={{ contest_id }}" |
| 173 | + creates: "{{ repo }}/final_standings.zip" |
| 174 | + dest: "{{ repo }}/final_standings.zip" |
| 175 | + headers: |
| 176 | + cookie: "{{ login_response.set_cookie }}" |
| 177 | + |
| 178 | + - name: "Fetch DOMjudge submissions" |
| 179 | + tags: all, fetch |
| 180 | + block: |
| 181 | + - name: Retrieve all submissions |
| 182 | + ansible.builtin.uri: |
| 183 | + url: "{{ dj_url }}/{{ dj_url_api_suffix }}/contests/{{ contest }}/submissions?strict=1" |
| 184 | + return_content: yes |
| 185 | + method: GET |
| 186 | + headers: |
| 187 | + Authorization: "{{ dj_basic_auth }}" |
| 188 | + register: "submissions" |
| 189 | + |
| 190 | + - name: Extract submission endpoints |
| 191 | + ansible.builtin.set_fact: |
| 192 | + submissions: "{{ submissions.json | json_query(jmesquery) }}" |
| 193 | + vars: |
| 194 | + jmesquery: "[].files[?mime == 'application/zip'][]" |
| 195 | + |
| 196 | + - name: Download submissions |
| 197 | + ansible.builtin.uri: |
| 198 | + url: "{{ dj_url }}/{{ dj_url_api_suffix }}/{{ item.href }}" |
| 199 | + return_content: yes |
| 200 | + method: GET |
| 201 | + headers: |
| 202 | + Authorization: "{{ dj_basic_auth }}" |
| 203 | + creates: "{{ repo }}/{{ item.href.split('/')[3] }}.zip" |
| 204 | + dest: "{{ repo }}/{{ item.href.split('/')[3] }}.zip" |
| 205 | + loop: "{{ submissions }}" |
0 commit comments