Files
michaelschiemer/.deployment-archive-20251030-111806/ansible/playbooks/setup-gitea-runner.yml

117 lines
3.4 KiB
YAML

---
# Ansible Playbook: Setup Gitea Actions Runner on Production Server
# Purpose: Install and configure Gitea Actions runner for automated deployments
# Usage: ansible-playbook -i inventory/production.yml playbooks/setup-gitea-runner.yml
- name: Setup Gitea Actions Runner for Production Deployments
hosts: production_server
become: yes
vars:
gitea_url: "https://git.michaelschiemer.de"
runner_name: "production-runner"
runner_labels: "docker,production,ubuntu"
runner_version: "0.2.6"
runner_install_dir: "/opt/gitea-runner"
runner_work_dir: "/home/deploy/gitea-runner-work"
runner_user: "deploy"
tasks:
- name: Create runner directories
file:
path: "{{ item }}"
state: directory
owner: "{{ runner_user }}"
group: "{{ runner_user }}"
mode: '0755'
loop:
- "{{ runner_install_dir }}"
- "{{ runner_work_dir }}"
- name: Download Gitea Act Runner binary
get_url:
url: "https://dl.gitea.com/act_runner/{{ runner_version }}/act_runner-{{ runner_version }}-linux-amd64"
dest: "{{ runner_install_dir }}/act_runner"
mode: '0755'
owner: "{{ runner_user }}"
- name: Check if runner is already registered
stat:
path: "{{ runner_install_dir }}/.runner"
register: runner_config
- name: Register runner with Gitea (manual step required)
debug:
msg: |
⚠️ MANUAL STEP REQUIRED:
1. Generate registration token in Gitea:
- Navigate to {{ gitea_url }}/admin/runners
- Click "Create new runner"
- Copy the registration token
2. SSH to production server and run:
sudo -u {{ runner_user }} {{ runner_install_dir }}/act_runner register \
--instance {{ gitea_url }} \
--token YOUR_REGISTRATION_TOKEN \
--name {{ runner_name }} \
--labels {{ runner_labels }}
3. Re-run this playbook to complete setup
when: not runner_config.stat.exists
- name: Create systemd service for runner
template:
src: ../templates/gitea-runner.service.j2
dest: /etc/systemd/system/gitea-runner.service
mode: '0644'
notify: Reload systemd
- name: Enable and start Gitea runner service
systemd:
name: gitea-runner
enabled: yes
state: started
when: runner_config.stat.exists
- name: Install Docker (if not present)
apt:
name:
- docker.io
- docker-compose
state: present
update_cache: yes
- name: Add runner user to docker group
user:
name: "{{ runner_user }}"
groups: docker
append: yes
- name: Ensure Docker service is running
systemd:
name: docker
state: started
enabled: yes
- name: Create Docker network for builds
docker_network:
name: gitea-runner-network
driver: bridge
- name: Display runner status
debug:
msg: |
✅ Gitea Runner Setup Complete
Runner Name: {{ runner_name }}
Install Dir: {{ runner_install_dir }}
Work Dir: {{ runner_work_dir }}
Check status: systemctl status gitea-runner
View logs: journalctl -u gitea-runner -f
handlers:
- name: Reload systemd
systemd:
daemon_reload: yes