110 lines
4.4 KiB
YAML
110 lines
4.4 KiB
YAML
---
|
|
- name: Check runner registration file exists
|
|
ansible.builtin.stat:
|
|
path: "{{ gitea_runner_data_dir }}/.runner"
|
|
register: runner_file_stat
|
|
|
|
- name: Read runner registration file
|
|
ansible.builtin.slurp:
|
|
src: "{{ gitea_runner_data_dir }}/.runner"
|
|
register: runner_file_content
|
|
when: runner_file_stat.stat.exists | default(false) | bool
|
|
|
|
- name: Parse runner registration data
|
|
ansible.builtin.set_fact:
|
|
runner_reg: >
|
|
{{ (runner_file_content.content | b64decode | from_json)
|
|
if (runner_file_content is defined and runner_file_content.content is defined)
|
|
else {} }}
|
|
when: runner_file_stat.stat.exists | default(false) | bool
|
|
|
|
- name: Verify runner container running (Docker mode)
|
|
ansible.builtin.shell: |
|
|
docker ps --filter "name=gitea-runner-{{ runner_name }}" --format "{{ '{{.Status}}' }}"
|
|
register: docker_check
|
|
changed_when: false
|
|
when: runner_mode == 'docker'
|
|
|
|
- name: Verify runner service active (Binary mode)
|
|
ansible.builtin.systemd:
|
|
name: "gitea-runner-{{ runner_mode }}@{{ runner_name }}"
|
|
state: started
|
|
register: service_check
|
|
when: runner_mode == 'binary'
|
|
|
|
- name: Validate runner installation
|
|
ansible.builtin.fail:
|
|
msg: >
|
|
Runner '{{ runner_name }}' is not properly installed:
|
|
{% if not (runner_file_stat.stat.exists | default(false)) %}
|
|
- Registration file (.runner) is missing. Registration may have failed.
|
|
{% endif %}
|
|
{% if runner_mode == 'docker' and not (docker_check.stdout | default('')) %}
|
|
- Docker container is not running.
|
|
{% endif %}
|
|
{% if runner_mode == 'binary' and not (service_check.status.ActiveState | default('')) == 'active' %}
|
|
- Systemd service is not active.
|
|
{% endif %}
|
|
when: >
|
|
not (runner_file_stat.stat.exists | default(false))
|
|
or (runner_mode == 'docker' and not (docker_check.stdout | default('')))
|
|
or (runner_mode == 'binary' and not (service_check.status.ActiveState | default('')) == 'active')
|
|
|
|
- name: Report runner status
|
|
ansible.builtin.debug:
|
|
msg: >
|
|
Runner '{{ runner_name }}' is installed and running.
|
|
Registered: {{ runner_file_stat.stat.exists | default(false) }}
|
|
{% if runner_reg.id is defined %}Runner ID: {{ runner_reg.id }}{% endif %}
|
|
{% if runner_reg.uuid is defined %}UUID: {{ runner_reg.uuid }}{% endif %}
|
|
{% if runner_reg.address is defined %}Gitea: {{ runner_reg.address }}{% endif %}
|
|
{% if runner_mode == 'docker' %}Container: {{ docker_check.stdout | default('unknown') }}{% endif %}
|
|
{% if runner_mode == 'binary' %}Service: {{ service_check.status.ActiveState | default('unknown') }}{% endif %}
|
|
|
|
- name: Optional Gitea API verification
|
|
when:
|
|
- gitea_url is defined
|
|
- gitea_admin_token is defined
|
|
- gitea_admin_token | length > 0
|
|
block:
|
|
- name: Check admin runners API
|
|
ansible.builtin.uri:
|
|
url: "{{ gitea_url }}/api/v1/admin/runners"
|
|
headers:
|
|
Authorization: "token {{ gitea_admin_token }}"
|
|
method: GET
|
|
status_code: [200, 401, 403, 404]
|
|
return_content: true
|
|
body_format: json
|
|
register: 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_admin_token }}"
|
|
method: GET
|
|
status_code: [200, 401, 403, 404]
|
|
return_content: true
|
|
body_format: json
|
|
register: 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: {{ admin_api_response.status | default('no response') }}.
|
|
Repo API: {{ repo_api_response.status | default('no response') }}.
|
|
{% if admin_api_response.json.runners | default([]) | selectattr('name', 'equalto', runner_name) | list | length > 0 %}
|
|
Runner found in admin API.
|
|
{% endif %}
|
|
{% if repo_api_response.json.runners | default([]) | selectattr('name', 'equalto', 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."
|