--- - 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 user service 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 }}" register: service_check changed_when: false - 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 not (service_check.stdout | default('') | trim) == 'active' %} - Systemd user service is not active. {% endif %} when: > not (runner_file_stat.stat.exists | default(false)) or not (service_check.stdout | default('') | trim) == '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 %} Service: {{ service_check.stdout | default('unknown') | trim }} - 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."