107 lines
4.4 KiB
YAML
107 lines
4.4 KiB
YAML
---
|
|
- name: Check runner registration file exists
|
|
ansible.builtin.stat:
|
|
path: "{{ gitea_runner_data_dir }}/.runner"
|
|
register: gitea_runner_file_stat
|
|
|
|
- name: Read runner registration file
|
|
ansible.builtin.slurp:
|
|
src: "{{ gitea_runner_data_dir }}/.runner"
|
|
register: gitea_runner_file_content
|
|
when: gitea_runner_file_stat.stat.exists | default(false) | bool
|
|
|
|
- name: Parse runner registration data
|
|
ansible.builtin.set_fact:
|
|
gitea_runner_reg: >
|
|
{{ (gitea_runner_file_content.content | b64decode | from_json)
|
|
if (gitea_runner_file_content is defined and gitea_runner_file_content.content is defined)
|
|
else {} }}
|
|
when: gitea_runner_file_stat.stat.exists | default(false) | bool
|
|
|
|
- name: Wait for runner user service to be active
|
|
ansible.builtin.command: systemctl --user is-active gitea-runner
|
|
become: true
|
|
become_user: "{{ gitea_runner_service_user }}"
|
|
environment:
|
|
XDG_RUNTIME_DIR: "/run/user/{{ gitea_runner_uid }}"
|
|
DBUS_SESSION_BUS_ADDRESS: "unix:path=/run/user/{{ gitea_runner_uid | default(0) }}/bus"
|
|
register: gitea_runner_service_check
|
|
changed_when: false
|
|
retries: 10
|
|
delay: 2
|
|
until: gitea_runner_service_check.stdout | default('') | trim == 'active'
|
|
when:
|
|
- gitea_runner_systemd_available.stat.exists
|
|
- gitea_runner_docker_rootless_setup
|
|
|
|
- name: Validate runner installation
|
|
ansible.builtin.fail:
|
|
msg: >
|
|
Runner '{{ gitea_runner_name }}' is not properly installed:
|
|
{% if not (gitea_runner_file_stat.stat.exists | default(false)) %}
|
|
- Registration file (.runner) is missing. Registration may have failed.
|
|
{% endif %}
|
|
{% if gitea_runner_docker_rootless_setup and not (gitea_runner_service_check.stdout | default('') | trim) == 'active' %}
|
|
- Systemd user service is not active.
|
|
{% endif %}
|
|
when: >
|
|
not (gitea_runner_file_stat.stat.exists | default(false))
|
|
or (gitea_runner_docker_rootless_setup and not (gitea_runner_service_check.stdout | default('') | trim) == 'active')
|
|
|
|
- name: Report runner status
|
|
ansible.builtin.debug:
|
|
msg: >
|
|
Runner '{{ gitea_runner_name }}' is installed and running.
|
|
Registered: {{ gitea_runner_file_stat.stat.exists | default(false) }}
|
|
{% if gitea_runner_reg.id is defined %}Runner ID: {{ gitea_runner_reg.id }}{% endif %}
|
|
{% if gitea_runner_reg.uuid is defined %}UUID: {{ gitea_runner_reg.uuid }}{% endif %}
|
|
{% if gitea_runner_reg.address is defined %}Gitea: {{ gitea_runner_reg.address }}{% endif %}
|
|
Service: {{ gitea_runner_service_check.stdout | default('unknown') | trim }}
|
|
|
|
- name: Optional Gitea API verification
|
|
when:
|
|
- gitea_url is defined
|
|
- gitea_runner_admin_token is defined
|
|
- gitea_runner_admin_token | length > 0
|
|
block:
|
|
- name: Check admin runners API
|
|
ansible.builtin.uri:
|
|
url: "{{ gitea_url }}/api/v1/admin/runners"
|
|
headers:
|
|
Authorization: "token {{ gitea_runner_admin_token }}"
|
|
method: GET
|
|
status_code: [200, 401, 403, 404]
|
|
return_content: true
|
|
body_format: json
|
|
register: gitea_runner_admin_api_response
|
|
ignore_errors: true
|
|
|
|
- name: Check repo runners API
|
|
ansible.builtin.uri:
|
|
url: "{{ gitea_url }}/api/v1/repos/{{ gitea_runner_test_repo | default('oblachno-oss/grm') }}/actions/runners"
|
|
headers:
|
|
Authorization: "token {{ gitea_runner_admin_token }}"
|
|
method: GET
|
|
status_code: [200, 401, 403, 404]
|
|
return_content: true
|
|
body_format: json
|
|
register: gitea_runner_repo_api_response
|
|
ignore_errors: true
|
|
|
|
- name: Report API status (informational only)
|
|
ansible.builtin.debug:
|
|
msg: >
|
|
API checks (informational only — not used for pass/fail):
|
|
Admin API: {{ gitea_runner_admin_api_response.status | default('no response') }}.
|
|
Repo API: {{ gitea_runner_repo_api_response.status | default('no response') }}.
|
|
{% if gitea_runner_admin_api_response.json.runners | default([]) | selectattr('name', 'equalto', gitea_runner_name) | list | length > 0 %}
|
|
Runner found in admin API.
|
|
{% endif %}
|
|
{% if gitea_runner_repo_api_response.json.runners | default([]) | selectattr('name', 'equalto', gitea_runner_name) | list | length > 0 %}
|
|
Runner found in repo API.
|
|
{% endif %}
|
|
rescue:
|
|
- name: API check failed
|
|
ansible.builtin.debug:
|
|
msg: "API verification skipped due to connection or permission error."
|