Skip to content

Commit

Permalink
Demonstrate first server setup
Browse files Browse the repository at this point in the history
  • Loading branch information
vmcj committed Sep 12, 2024
1 parent 5af9d1a commit 17227b9
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 77 deletions.
6 changes: 6 additions & 0 deletions provision-contest/ansible/hosts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ ansible_python_interpreter=/usr/bin/python3
domserver
judgehost
grafana
scriptserver
admin

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

[scriptserver]
# During the WFs we use one of the ccsadmin machines
# Doesn't matter which (admin) machine but in the past we used 1 as that runs ansible
domjudge-ccsadmin1 ansible_host=10.3.3.224

[analyst-domserver]
# Discuss if we can have this host dualhomed in blue to make management easier.\
# Looking at the IP sheet that would mean that our emergency laptop needs to move.
Expand Down
74 changes: 43 additions & 31 deletions provision-contest/ansible/roles/script_server/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,43 +1,55 @@
---
script_server_url: https://github.com/bugy/script-server/releases/download/1.18.0/script-server.zip
script_server_port: 5000

script_server_admin_users: &admin_users
# hostnames or ips
- backup
- 127.0.0.1

# ansible hostgroups to ignore
script_server_ignored_groups:
- 'all'
- 'ungrouped'
- 'contestants'
- 'contestants_wf46'
- 'contestants_wf47'

SCRIPT_SERVER_PORT: 5000

script_server_commands:
- name: run-lastminute
description: Runs the ansible playbook lastminute.yml
group: ansible # for organization in script-server
allowed_users:
- backup # or 10.3.3.210 (the ansible template will resolve names to IPs)
- name: make-invocations
description: Run the make targets as last years
parameters:
- name: make_pattern
type: multiselect
separator: ' '
values:
- admin
- domserver
- judgehost
- grafana
- cds
content: |
#!/bin/bash
set -euxo pipefail
if [ "$make_pattern" = "" ]; then
exit 1
fi
cd /home/domjudge/domjudge-scripts-checkout/provision-contest/ansible
for make_single in $make_pattern; do
make "$make_single"
done
- name: ansible-admin
description: (Re)configure the (other) admin machines
content: |
#!/usr/bin/bash
echo "hello world $HOSTPATTERN"
#!/bin/bash
set -euxo pipefail
if [ "$host_pattern" = "" ]; then
exit 1
fi
if [ "$tag_pattern" != "" ]; then
tag="--tags $tag_pattern"
fi
cd /home/domjudge/domjudge-scripts-checkout/provision-contest/ansible
ansible-playbook --limit $host_pattern ${tag:-} admin.yml
parameters:
- name: host_pattern
# pass_as: env_variable # this is default
# env_var: host_pattern # default is same as name
type: list
values:
- all
- backup
- packages
- scoreboard
- cds
type: multiselect
values: "{{ groups['admin'] }}"
default: "{{ groups['admin'] | difference(['domjudge-ccsadmin2']) }}"
- name: tag_pattern
type: "multiselect"
values: ["reboot"]
default: []

script_server_command_defaults:
output_format: terminal
# scheduling: # Don't allow scheduling, the ui for it is not good...
# enabled: false
# enabled: false
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.zip
Binary file not shown.
7 changes: 1 addition & 6 deletions provision-contest/ansible/roles/script_server/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@
state: directory

- name: Install script-server
when: ICPC_IMAGE
unarchive:
src: "https://github.com/bugy/script-server/releases/download/1.18.0/script-server.zip"

name: Install script-server
when: ICPC_IMAGE
unarchive:
src: "script-server.zip"
Expand Down Expand Up @@ -82,7 +77,7 @@
- name: Create script config definitions
ansible.builtin.template:
src: command_template.yml.j2
dest: /opt/script-server/conf/runners/{{ item.name }}.yml
dest: /opt/script-server/conf/runners/{{ item.name }}.yaml
mode: "0644"
with_items: "{{ script_server_commands }}"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
---
{% set _unused_content = item.pop('content') %}
{% set parameters = item.pop('parameters') %}
{% set admin_users = item.pop('admin_users', []) + script_server_admin_users %}
{% set allowed_users = item.pop('allowed_users', []) %}
{% set parameters = item.pop('parameters', []) %}
{% set admin_users = groups['admin'] %}
{% set allowed_users = groups['onprem'] %}
{# set admin_users = (admin_users if ( admin_users | type_debug == "list" ) else [admin_users]) #}
{# set allowed_users = (allowed_users if ( allowed_users | type_debug == "list" ) else [allowed_users]) #}
{{
script_server_command_defaults |
combine(item) |
to_nice_yaml
}}

{% if admin_users %}
admin_users:
- 127.0.0.1
{% for u in admin_users %}
- {{ lookup('ip', u) }}
- {{ hostvars[u].ansible_host }}
{% endfor %}
{% endif %}
{% if allowed_users %}
allowed_users:
{% for u in (allowed_users + admin_users) %}
- {{ lookup('ip', u) }}
skipped_allowed_users:
- 127.0.0.1
{% for u in (allowed_users + admin_users)|unique %}
- {{ hostvars[u].ansible_host }}
{% endfor %}
{% endif %}

Expand All @@ -37,6 +40,5 @@ parameters:
{% endfor %}
{% endif %}


# assume default path for the script file
script_path: conf/scripts/{{ item.name }}
Original file line number Diff line number Diff line change
@@ -1,40 +1,13 @@
{
"title": "sysops script server",
"port": {{ script_server_port }},
"port": {{ SCRIPT_SERVER_PORT }},
"access": {
"trusted_ips": [
{% for group in groups if group not in script_server_ignored_groups %}
{%- for host in groups[group] -%}
"{{ hostvars[host].ansible_host}}",
"admin_users": [
{%- for host in groups['admin'] -%}
"{{ hostvars[host].ansible_host}}",
{% endfor %}
{%- endfor -%}

{% for u in script_server_admin_users %}"{{ lookup('ip', u)}}", {% endfor %}"127.0.0.1"
],
"allowed_users": [
{% for group in groups if group not in script_server_ignored_groups %}
{%- for host in groups[group] -%}
"{{ hostvars[host].ansible_host}}",
{% endfor -%}
{%- endfor -%}
"127.0.0.1"
],
"admin_users": [{% for u in script_server_admin_users %}"{{ lookup('ip', u)}}", {% endfor %}"127.0.0.1"],
"groups": {
{% for group in groups if group not in script_server_ignored_groups -%}
"{{group}}": [
{% for host in groups[group] -%}
"{{ hostvars[host].ansible_host}}" {{ ", " if not loop.last else "" }}
{% endfor -%}
],
{% endfor -%}
"all": [
{% for group in groups if group not in script_server_ignored_groups -%}
"{{ group }}",
{% endfor -%}
"@admin_users"
]
}
]
},
"logging": {
"execution_file": "$DATE-$ID.log",
Expand Down
20 changes: 20 additions & 0 deletions provision-contest/ansible/scriptserver.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---

- hosts: scriptserver
vars:
host_type: scriptserver
become: true
handlers:
- include: handlers.yml
roles:
- role: base_packages
tags: base_packages
- role: icpc_fixes
tags: icpc_fixes
when: ICPC_IMAGE
- role: system_fixes
tags: system_fixes
- role: hosts
tags: hosts
- role: script_server
tags: script_server

0 comments on commit 17227b9

Please sign in to comment.