feat: Add Ansible playbooks to fix Gitea runner configuration
- Add fix-gitea-runner-config.yml to diagnose runner configuration issues - Add register-gitea-runner.yml to re-register runner with correct Gitea URL - Check for GitHub URLs in runner configuration (should only use git.michaelschiemer.de) - Verify .env file has correct GITEA_INSTANCE_URL - Fixes 504 timeouts caused by runner trying to connect to GitHub fallback
This commit is contained in:
142
deployment/ansible/playbooks/register-gitea-runner.yml
Normal file
142
deployment/ansible/playbooks/register-gitea-runner.yml
Normal file
@@ -0,0 +1,142 @@
|
||||
---
|
||||
- name: Register Gitea Runner with Correct Instance URL
|
||||
hosts: production
|
||||
gather_facts: yes
|
||||
become: no
|
||||
|
||||
vars:
|
||||
gitea_runner_path: "{{ runner_path | default('/home/deploy/deployment/gitea-runner') }}"
|
||||
gitea_instance_url: "https://git.michaelschiemer.de"
|
||||
runner_registration_token: "{{ runner_registration_token | default('') }}"
|
||||
runner_name: "{{ runner_name | default('dev-runner-01') }}"
|
||||
runner_labels: "{{ runner_labels | default('ubuntu-latest:docker://node:16-bullseye,ubuntu-22.04:docker://node:16-bullseye,php-ci:docker://php-ci:latest') }}"
|
||||
runner_container_name: "gitea-runner"
|
||||
|
||||
tasks:
|
||||
- name: Fail if registration token is not provided
|
||||
fail:
|
||||
msg: "runner_registration_token must be provided via -e 'runner_registration_token=<token>'"
|
||||
when: runner_registration_token | string | trim == ''
|
||||
|
||||
- name: Check if Gitea runner directory exists
|
||||
stat:
|
||||
path: "{{ gitea_runner_path }}"
|
||||
register: runner_dir_exists
|
||||
|
||||
- name: Fail if runner directory does not exist
|
||||
fail:
|
||||
msg: "Gitea runner directory not found at {{ gitea_runner_path }}"
|
||||
when: not runner_dir_exists.stat.exists
|
||||
|
||||
- name: Stop runner container if running
|
||||
shell: |
|
||||
cd {{ gitea_runner_path }}
|
||||
docker compose stop {{ runner_container_name }}
|
||||
register: stop_result
|
||||
changed_when: stop_result.rc == 0
|
||||
failed_when: false
|
||||
|
||||
- name: Backup existing .runner file
|
||||
copy:
|
||||
src: "{{ gitea_runner_path }}/data/.runner"
|
||||
dest: "{{ gitea_runner_path }}/data/.runner.backup.{{ ansible_date_time.epoch }}"
|
||||
remote_src: yes
|
||||
when: runner_file_exists.stat.exists
|
||||
register: runner_file_exists
|
||||
ignore_errors: yes
|
||||
|
||||
- name: Check if .runner file exists
|
||||
stat:
|
||||
path: "{{ gitea_runner_path }}/data/.runner"
|
||||
register: runner_file_exists
|
||||
|
||||
- name: Remove existing .runner file
|
||||
file:
|
||||
path: "{{ gitea_runner_path }}/data/.runner"
|
||||
state: absent
|
||||
when: runner_file_exists.stat.exists
|
||||
|
||||
- name: Update .env file with correct configuration
|
||||
lineinfile:
|
||||
path: "{{ gitea_runner_path }}/.env"
|
||||
regexp: '^{{ item.key }}='
|
||||
line: "{{ item.key }}={{ item.value }}"
|
||||
create: yes
|
||||
loop:
|
||||
- { key: 'GITEA_INSTANCE_URL', value: '{{ gitea_instance_url }}' }
|
||||
- { key: 'GITEA_RUNNER_REGISTRATION_TOKEN', value: '{{ runner_registration_token }}' }
|
||||
- { key: 'GITEA_RUNNER_NAME', value: '{{ runner_name }}' }
|
||||
- { key: 'GITEA_RUNNER_LABELS', value: '{{ runner_labels }}' }
|
||||
no_log: true
|
||||
|
||||
- name: Start runner services
|
||||
shell: |
|
||||
cd {{ gitea_runner_path }}
|
||||
docker compose up -d
|
||||
register: start_services
|
||||
changed_when: start_services.rc == 0
|
||||
|
||||
- name: Wait for services to be ready
|
||||
pause:
|
||||
seconds: 5
|
||||
|
||||
- name: Register runner with correct Gitea instance
|
||||
shell: |
|
||||
cd {{ gitea_runner_path }}
|
||||
docker compose exec -T {{ runner_container_name }} act_runner register \
|
||||
--instance "{{ gitea_instance_url }}" \
|
||||
--token "{{ runner_registration_token }}" \
|
||||
--name "{{ runner_name }}" \
|
||||
--labels "{{ runner_labels }}"
|
||||
register: register_result
|
||||
no_log: true
|
||||
changed_when: register_result.rc == 0
|
||||
|
||||
- name: Display registration result
|
||||
debug:
|
||||
msg: |
|
||||
Runner Registration Result:
|
||||
{{ register_result.stdout | default('No output') }}
|
||||
when: register_result.rc == 0
|
||||
|
||||
- name: Verify .runner file was created
|
||||
stat:
|
||||
path: "{{ gitea_runner_path }}/data/.runner"
|
||||
register: runner_file_created
|
||||
|
||||
- name: Check .runner file for correct instance URL
|
||||
shell: |
|
||||
grep -i "{{ gitea_instance_url }}" "{{ gitea_runner_path }}/data/.runner" 2>/dev/null || echo "URL_NOT_FOUND"
|
||||
register: runner_url_check
|
||||
when: runner_file_created.stat.exists
|
||||
changed_when: false
|
||||
|
||||
- name: Check .runner file for GitHub URLs
|
||||
shell: |
|
||||
grep -i "github.com" "{{ gitea_runner_path }}/data/.runner" 2>/dev/null || echo "NO_GITHUB_URLS"
|
||||
register: runner_github_check
|
||||
when: runner_file_created.stat.exists
|
||||
changed_when: false
|
||||
|
||||
- name: Display final status
|
||||
debug:
|
||||
msg: |
|
||||
========================================
|
||||
Gitea Runner Registration Status
|
||||
========================================
|
||||
Registration: {{ '✅ SUCCESS' if register_result.rc == 0 else '❌ FAILED' }}
|
||||
Runner File Created: {{ '✅ YES' if runner_file_created.stat.exists else '❌ NO' }}
|
||||
Contains Correct URL: {{ '✅ YES' if 'URL_NOT_FOUND' not in runner_url_check.stdout else '❌ NO' }}
|
||||
Contains GitHub URLs: {{ '❌ YES' if 'NO_GITHUB_URLS' not in runner_github_check.stdout else '✅ NO' }}
|
||||
========================================
|
||||
|
||||
{% if register_result.rc == 0 and runner_file_created.stat.exists %}
|
||||
✅ Runner registered successfully with {{ gitea_instance_url }}!
|
||||
|
||||
Check runner status:
|
||||
{{ gitea_instance_url }}/admin/actions/runners
|
||||
{% else %}
|
||||
❌ Registration failed. Check logs:
|
||||
docker logs {{ runner_container_name }}
|
||||
{% endif %}
|
||||
|
||||
Reference in New Issue
Block a user