Skip to content

Commit 8810588

Browse files
committedSep 12, 2024·
Demonstrate first server setup
1 parent c6165fb commit 8810588

File tree

8 files changed

+86
-77
lines changed

8 files changed

+86
-77
lines changed
 

‎provision-contest/ansible/hosts

+6
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ ansible_python_interpreter=/usr/bin/python3
99
domserver
1010
judgehost
1111
grafana
12+
scriptserver
1213
admin
1314

1415
[online:children]
@@ -70,6 +71,11 @@ domjudge-ccsadmin5 ansible_host=10.3.3.228
7071
# Doesn't matter which (admin) machine but should not be 1 as that runs ansible
7172
domjudge-ccsadmin2 ansible_host=10.3.3.225
7273

74+
[scriptserver]
75+
# During the WFs we use one of the ccsadmin machines
76+
# Doesn't matter which (admin) machine but in the past we used 1 as that runs ansible
77+
domjudge-ccsadmin1 ansible_host=10.3.3.224
78+
7379
[analyst-domserver]
7480
# Discuss if we can have this host dualhomed in blue to make management easier.\
7581
# Looking at the IP sheet that would mean that our emergency laptop needs to move.
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,55 @@
11
---
2-
script_server_url: https://github.com/bugy/script-server/releases/download/1.18.0/script-server.zip
3-
script_server_port: 5000
4-
5-
script_server_admin_users: &admin_users
6-
# hostnames or ips
7-
- backup
8-
- 127.0.0.1
9-
10-
# ansible hostgroups to ignore
11-
script_server_ignored_groups:
12-
- 'all'
13-
- 'ungrouped'
14-
- 'contestants'
15-
- 'contestants_wf46'
16-
- 'contestants_wf47'
17-
2+
SCRIPT_SERVER_PORT: 5000
183

194
script_server_commands:
20-
- name: run-lastminute
21-
description: Runs the ansible playbook lastminute.yml
22-
group: ansible # for organization in script-server
23-
allowed_users:
24-
- backup # or 10.3.3.210 (the ansible template will resolve names to IPs)
5+
- name: make-invocations
6+
description: Run the make targets as last years
7+
parameters:
8+
- name: make_pattern
9+
type: multiselect
10+
separator: ' '
11+
values:
12+
- admin
13+
- domserver
14+
- judgehost
15+
- grafana
16+
- cds
17+
content: |
18+
#!/bin/bash
19+
set -euxo pipefail
20+
if [ "$make_pattern" = "" ]; then
21+
exit 1
22+
fi
23+
cd /home/domjudge/domjudge-scripts-checkout/provision-contest/ansible
24+
for make_single in $make_pattern; do
25+
make "$make_single"
26+
done
27+
- name: ansible-admin
28+
description: (Re)configure the (other) admin machines
2529
content: |
26-
#!/usr/bin/bash
27-
echo "hello world $HOSTPATTERN"
30+
#!/bin/bash
31+
set -euxo pipefail
32+
if [ "$host_pattern" = "" ]; then
33+
exit 1
34+
fi
35+
if [ "$tag_pattern" != "" ]; then
36+
tag="--tags $tag_pattern"
37+
fi
38+
cd /home/domjudge/domjudge-scripts-checkout/provision-contest/ansible
39+
ansible-playbook --limit $host_pattern ${tag:-} admin.yml
2840
parameters:
2941
- name: host_pattern
3042
# pass_as: env_variable # this is default
3143
# env_var: host_pattern # default is same as name
32-
type: list
33-
values:
34-
- all
35-
- backup
36-
- packages
37-
- scoreboard
38-
- cds
44+
type: multiselect
45+
values: "{{ groups['admin'] }}"
46+
default: "{{ groups['admin'] | difference(['domjudge-ccsadmin2']) }}"
47+
- name: tag_pattern
48+
type: "multiselect"
49+
values: ["reboot"]
50+
default: []
3951

4052
script_server_command_defaults:
4153
output_format: terminal
4254
# scheduling: # Don't allow scheduling, the ui for it is not good...
43-
# enabled: false
55+
# enabled: false
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.zip
Binary file not shown.

‎provision-contest/ansible/roles/script_server/tasks/main.yml

+1-6
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,6 @@
1515
state: directory
1616

1717
- name: Install script-server
18-
when: ICPC_IMAGE
19-
unarchive:
20-
src: "https://github.com/bugy/script-server/releases/download/1.18.0/script-server.zip"
21-
22-
name: Install script-server
2318
when: ICPC_IMAGE
2419
unarchive:
2520
src: "script-server.zip"
@@ -82,7 +77,7 @@
8277
- name: Create script config definitions
8378
ansible.builtin.template:
8479
src: command_template.yml.j2
85-
dest: /opt/script-server/conf/runners/{{ item.name }}.yml
80+
dest: /opt/script-server/conf/runners/{{ item.name }}.yaml
8681
mode: "0644"
8782
with_items: "{{ script_server_commands }}"
8883

‎provision-contest/ansible/roles/script_server/templates/command_template.yaml.j2 ‎provision-contest/ansible/roles/script_server/templates/command_template.yml.j2

+10-8
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,28 @@
11
---
22
{% set _unused_content = item.pop('content') %}
3-
{% set parameters = item.pop('parameters') %}
4-
{% set admin_users = item.pop('admin_users', []) + script_server_admin_users %}
5-
{% set allowed_users = item.pop('allowed_users', []) %}
3+
{% set parameters = item.pop('parameters', []) %}
4+
{% set admin_users = groups['admin'] %}
5+
{% set allowed_users = groups['onprem'] %}
66
{# set admin_users = (admin_users if ( admin_users | type_debug == "list" ) else [admin_users]) #}
77
{# set allowed_users = (allowed_users if ( allowed_users | type_debug == "list" ) else [allowed_users]) #}
88
{{
99
script_server_command_defaults |
1010
combine(item) |
1111
to_nice_yaml
1212
}}
13+
1314
{% if admin_users %}
1415
admin_users:
16+
- 127.0.0.1
1517
{% for u in admin_users %}
16-
- {{ lookup('ip', u) }}
18+
- {{ hostvars[u].ansible_host }}
1719
{% endfor %}
1820
{% endif %}
1921
{% if allowed_users %}
20-
allowed_users:
21-
{% for u in (allowed_users + admin_users) %}
22-
- {{ lookup('ip', u) }}
22+
skipped_allowed_users:
23+
- 127.0.0.1
24+
{% for u in (allowed_users + admin_users)|unique %}
25+
- {{ hostvars[u].ansible_host }}
2326
{% endfor %}
2427
{% endif %}
2528

@@ -37,6 +40,5 @@ parameters:
3740
{% endfor %}
3841
{% endif %}
3942

40-
4143
# assume default path for the script file
4244
script_path: conf/scripts/{{ item.name }}

‎provision-contest/ansible/roles/script_server/templates/conf.json.j2

+5-32
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,13 @@
11
{
22
"title": "sysops script server",
3-
"port": {{ script_server_port }},
3+
"port": {{ SCRIPT_SERVER_PORT }},
44
"access": {
5-
"trusted_ips": [
6-
{% for group in groups if group not in script_server_ignored_groups %}
7-
{%- for host in groups[group] -%}
8-
"{{ hostvars[host].ansible_host}}",
5+
"admin_users": [
6+
{%- for host in groups['admin'] -%}
7+
"{{ hostvars[host].ansible_host}}",
98
{% endfor %}
10-
{%- endfor -%}
11-
12-
{% for u in script_server_admin_users %}"{{ lookup('ip', u)}}", {% endfor %}"127.0.0.1"
13-
],
14-
"allowed_users": [
15-
{% for group in groups if group not in script_server_ignored_groups %}
16-
{%- for host in groups[group] -%}
17-
"{{ hostvars[host].ansible_host}}",
18-
{% endfor -%}
19-
{%- endfor -%}
209
"127.0.0.1"
21-
],
22-
"admin_users": [{% for u in script_server_admin_users %}"{{ lookup('ip', u)}}", {% endfor %}"127.0.0.1"],
23-
"groups": {
24-
{% for group in groups if group not in script_server_ignored_groups -%}
25-
"{{group}}": [
26-
{% for host in groups[group] -%}
27-
"{{ hostvars[host].ansible_host}}" {{ ", " if not loop.last else "" }}
28-
{% endfor -%}
29-
],
30-
{% endfor -%}
31-
"all": [
32-
{% for group in groups if group not in script_server_ignored_groups -%}
33-
"{{ group }}",
34-
{% endfor -%}
35-
"@admin_users"
36-
]
37-
}
10+
]
3811
},
3912
"logging": {
4013
"execution_file": "$DATE-$ID.log",
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
3+
- hosts: scriptserver
4+
vars:
5+
host_type: scriptserver
6+
become: true
7+
handlers:
8+
- include: handlers.yml
9+
roles:
10+
- role: base_packages
11+
tags: base_packages
12+
- role: icpc_fixes
13+
tags: icpc_fixes
14+
when: ICPC_IMAGE
15+
- role: system_fixes
16+
tags: system_fixes
17+
- role: hosts
18+
tags: hosts
19+
- role: script_server
20+
tags: script_server

0 commit comments

Comments
 (0)
Please sign in to comment.