feat: Swapped tofu init scripting for ansible scripting

This commit is contained in:
2026-07-13 21:23:31 +01:00
parent cf5504281c
commit c12a507fc1
34 changed files with 471 additions and 501 deletions
+55
View File
@@ -0,0 +1,55 @@
---
# Copies services/<service_group>/ to the server and renders the files that
# used to be generated by OpenTofu (services/<host>/.env and, for dev,
# Runners/docker-compose.yml) - replaces the null_resource.deploy_services +
# local_file provisioners previously in infra/modules/<host>/main.tf.
- name: Ensure services directory exists on the host
ansible.builtin.file:
path: "/home/{{ deploy_user }}/services/{{ service_group }}"
state: directory
mode: "0755"
- name: Copy static service files (compose files, scripts, configs)
ansible.builtin.copy:
src: "{{ services_root }}/{{ service_group }}/"
dest: "/home/{{ deploy_user }}/services/{{ service_group }}/"
mode: preserve
- name: Look up this host's data volume
when: service_group in ['dev', 'prod']
delegate_to: localhost
become: false
hetzner.hcloud.hcloud_volume_info:
api_token: "{{ hcloud_token }}"
name: "{{ service_group }}-storage"
register: _volume_info
# Hetzner's automount tooling always mounts an auto-mounted volume at
# /mnt/HC_Volume_<volume-id> - deterministic once the volume exists.
- name: Compute DATA_DIR from the volume's id
when: service_group in ['dev', 'prod']
ansible.builtin.set_fact:
data_dir: "/mnt/HC_Volume_{{ _volume_info.hcloud_volume_info[0].id }}"
- name: Render DATA_DIR into .env (auto-loaded by docker compose)
when: service_group in ['dev', 'prod']
ansible.builtin.template:
src: env.j2
dest: "/home/{{ deploy_user }}/services/{{ service_group }}/.env"
mode: "0644"
- name: Render Gitea Actions runner compose file
when: service_group == 'dev'
ansible.builtin.template:
src: runners-docker-compose.yml.j2
dest: "/home/{{ deploy_user }}/services/dev/Runners/docker-compose.yml"
mode: "0644"
- name: Make spinup/spindown scripts executable
ansible.builtin.file:
path: "/home/{{ deploy_user }}/services/{{ service_group }}/{{ item }}"
mode: "0755"
loop:
- spinup.sh
- spindown.sh
+1
View File
@@ -0,0 +1 @@
DATA_DIR={{ data_dir }}
@@ -0,0 +1,35 @@
# Generated by Ansible from dev_runner_count - do not hand-edit.
# To change the number of runners, edit dev_runner_count in
# ansible/group_vars/role_dev.yml and re-run playbooks/deploy.yml.
# To change their shape, edit this template instead.
#
# GITEA_RUNNER_REGISTRATION_TOKEN is intentionally left as a compose variable
# (not baked in here) - services/dev/spinup.sh generates a fresh token and
# writes it to Runners/.env immediately before starting these containers.
#
# /data lives on dev's volume ({{ data_dir }}) so runner identity survives a
# server rebuild - baked in directly rather than via .env, since Runners/.env
# is already reserved for the registration token above and gets overwritten
# on every deploy.
services:
{% for i in range(1, dev_runner_count + 1) %}
runner-{{ i }}:
image: gitea/act_runner:latest
container_name: gitea_runner_{{ i }}
volumes:
- ./config.yaml:/config.yaml
- {{ data_dir }}/gitea_runner_{{ i }}:/data
- /var/run/docker.sock:/var/run/docker.sock
networks:
- proxy
environment:
CONFIG_FILE: /config.yaml
GITEA_INSTANCE_URL: "https://git.luke-else.co.uk"
GITEA_RUNNER_REGISTRATION_TOKEN: "${GITEA_RUNNER_REGISTRATION_TOKEN}"
GITEA_RUNNER_NAME: "CICD#{{ i }}"
restart: unless-stopped
{% endfor %}
networks:
proxy:
external: true