|
15 | 15 | project_src: /opt/glitchtip
|
16 | 16 | files:
|
17 | 17 | - docker-compose.yaml
|
| 18 | + |
| 19 | +- name: Assume we don't have an account if we didn't specify the token |
| 20 | + when: not GLITCHTIP_TOKEN |
| 21 | + block: |
| 22 | + - name: Wait for stable GlitchTip migrations |
| 23 | + ansible.builtin.wait_for: |
| 24 | + timeout: 10 |
| 25 | + - name: Fetch CSRF from login page |
| 26 | + ansible.builtin.uri: |
| 27 | + method: GET |
| 28 | + return_content: yes |
| 29 | + url: "http://localhost:{{ GLITCHTIP_PORT }}/api/docs" |
| 30 | + register: glitchtip_csrf |
| 31 | + |
| 32 | + - name: Register DOMjudge account |
| 33 | + ansible.builtin.uri: |
| 34 | + method: POST |
| 35 | + return_content: yes |
| 36 | + url: "http://localhost:{{ GLITCHTIP_PORT }}/_allauth/browser/v1/auth/signup" |
| 37 | + status_code: 200 |
| 38 | + headers: |
| 39 | + Cookie: "{{ glitchtip_csrf.cookies_string }}" |
| 40 | + X-CSRFTOKEN: "{{ glitchtip_csrf.cookies_string | regex_search('csrftoken=([a-zA-Z0-9]+)', '\\1') | first }}" |
| 41 | + body: |
| 42 | + |
| 43 | + password: "{{ GLITCHTIP_PASSWORD }}" |
| 44 | + body_format: json |
| 45 | + register: glitchtip_register |
| 46 | + |
| 47 | + - name: Create API token |
| 48 | + ansible.builtin.uri: |
| 49 | + method: POST |
| 50 | + return_content: yes |
| 51 | + url: "http://localhost:{{ GLITCHTIP_PORT }}/api/0/api-tokens/" |
| 52 | + status_code: 201 |
| 53 | + headers: |
| 54 | + Cookie: "{{ glitchtip_register.cookies_string }}" |
| 55 | + X-CSRFTOKEN: "{{ glitchtip_register.cookies_string | regex_search('csrftoken=([a-zA-Z0-9]+)', '\\1') | first }}" |
| 56 | + body: |
| 57 | + label: "ansible" |
| 58 | + scopes: [ |
| 59 | + "project:read", |
| 60 | + "project:write", |
| 61 | + "project:admin", |
| 62 | + "project:releases", |
| 63 | + "team:read", |
| 64 | + "team:write", |
| 65 | + "team:admin", |
| 66 | + "event:read", |
| 67 | + "event:write", |
| 68 | + "event:admin", |
| 69 | + "org:read", |
| 70 | + "org:write", |
| 71 | + "org:admin", |
| 72 | + "member:read", |
| 73 | + "member:write", |
| 74 | + "member:admin" |
| 75 | + ] |
| 76 | + body_format: json |
| 77 | + register: glitchtip_token |
| 78 | + |
| 79 | + - name: Set API token |
| 80 | + ansible.builtin.set_fact: |
| 81 | + GLITCHTIP_TOKEN: "{{ glitchtip_token.json.token }}" |
| 82 | + |
| 83 | +- name: Check for existing organizations |
| 84 | + ansible.builtin.uri: |
| 85 | + method: GET |
| 86 | + return_content: yes |
| 87 | + url: "http://localhost:{{ GLITCHTIP_PORT }}/api/0/organizations/" |
| 88 | + headers: |
| 89 | + Authorization: "Bearer {{ GLITCHTIP_TOKEN }}" |
| 90 | + register: glitchtip_org |
| 91 | + |
| 92 | +- name: Create DOMjudge organization |
| 93 | + when: glitchtip_org.json | community.general.json_query("[?name=='DOMjudge']") == [] |
| 94 | + ansible.builtin.uri: |
| 95 | + method: POST |
| 96 | + return_content: yes |
| 97 | + url: "http://localhost:{{ GLITCHTIP_PORT }}/api/0/organizations/" |
| 98 | + status_code: 201 |
| 99 | + headers: |
| 100 | + Authorization: "Bearer {{ GLITCHTIP_TOKEN }}" |
| 101 | + body: |
| 102 | + name: "DOMjudge" |
| 103 | + body_format: json |
| 104 | + register: glitchtip_org |
| 105 | + |
| 106 | +- name: Check for existing teams |
| 107 | + ansible.builtin.uri: |
| 108 | + method: GET |
| 109 | + return_content: yes |
| 110 | + url: "http://localhost:{{ GLITCHTIP_PORT }}/api/0/organizations/domjudge/teams/" |
| 111 | + headers: |
| 112 | + Authorization: "Bearer {{ GLITCHTIP_TOKEN }}" |
| 113 | + register: glitchtip_team |
| 114 | + |
| 115 | +- name: Create DOMjudge team |
| 116 | + when: glitchtip_team.json | community.general.json_query("[?slug=='DOMjudge']") == [] |
| 117 | + ansible.builtin.uri: |
| 118 | + method: POST |
| 119 | + return_content: yes |
| 120 | + url: "http://localhost:{{ GLITCHTIP_PORT }}/api/0/organizations/domjudge/teams/" |
| 121 | + status_code: 201 |
| 122 | + headers: |
| 123 | + Authorization: "Bearer {{ GLITCHTIP_TOKEN }}" |
| 124 | + body: |
| 125 | + slug: "DOMjudge" |
| 126 | + body_format: json |
| 127 | + register: glitchtip_team |
| 128 | + |
| 129 | +- name: Check for existing projects |
| 130 | + ansible.builtin.uri: |
| 131 | + method: GET |
| 132 | + return_content: yes |
| 133 | + url: "http://localhost:{{ GLITCHTIP_PORT }}/api/0/teams/domjudge/DOMjudge/projects/" |
| 134 | + headers: |
| 135 | + Authorization: "Bearer {{ GLITCHTIP_TOKEN }}" |
| 136 | + register: glitchtip_proj |
| 137 | + |
| 138 | +- name: Create DOMjudge projects |
| 139 | + when: glitchtip_proj.json | community.general.json_query("[?name=='{{ item }}']") == [] |
| 140 | + ansible.builtin.uri: |
| 141 | + method: POST |
| 142 | + return_content: yes |
| 143 | + url: "http://localhost:{{ GLITCHTIP_PORT }}/api/0/teams/domjudge/DOMjudge/projects/" |
| 144 | + status_code: 201 |
| 145 | + headers: |
| 146 | + Authorization: "Bearer {{ GLITCHTIP_TOKEN }}" |
| 147 | + body: |
| 148 | + name: "{{ item }}" |
| 149 | + platform: "php-symfony" |
| 150 | + body_format: json |
| 151 | + loop: "{{ ['setup-phase'] + groups['domserver'] }}" |
| 152 | + |
| 153 | +- name: Check for existing monitors |
| 154 | + ansible.builtin.uri: |
| 155 | + method: GET |
| 156 | + return_content: yes |
| 157 | + url: "http://localhost:{{ GLITCHTIP_PORT }}/api/0/organizations/domjudge/monitors/" |
| 158 | + headers: |
| 159 | + Authorization: "Bearer {{ GLITCHTIP_TOKEN }}" |
| 160 | + register: glitchtip_mon |
| 161 | + |
| 162 | +- name: Create DOMjudge monitors |
| 163 | + when: glitchtip_mon.json | community.general.json_query("[?name=='{{ item }}']") == [] |
| 164 | + loop: "{{ groups['domserver'] }}" |
| 165 | + include_tasks: create-monitor.yml |
0 commit comments