Every role scenario with a converge now runs check right before it (a fresh host) and right after it (a configured host), and a script test fails a scenario without both. pihole and pve_lxc move their second check from after idempotence to after converge to match. The roles that failed under --check on a fresh host get the two allowed guards: cloudflared, docker, gitea, gitea_runner, traefik and user_management. ufw and fail2ban preview only a host where their package is installed, as their READMEs now say. Closes #134 Assisted-by: Claude Code
82 lines
3.6 KiB
YAML
82 lines
3.6 KiB
YAML
---
|
|
- name: Get current runner version
|
|
become: true
|
|
ansible.builtin.command:
|
|
argv: ["{{ gitea_runner_install_dir }}/gitea-runner", --version]
|
|
register: gitea_runner_version_cmd
|
|
changed_when: false
|
|
# Failure is expected when the binary is missing (rc 2): empty stdout falls through to 0.0.0
|
|
# below, which triggers the install path.
|
|
failed_when: false
|
|
# Read-only, so it also runs in the --check preview. Skipped there, stdout would be empty, the version
|
|
# would fall back to 0.0.0 and an up-to-date binary would look like it needs an install.
|
|
check_mode: false
|
|
tags: [gitea_runner, update]
|
|
|
|
- name: Extract installed version
|
|
ansible.builtin.set_fact:
|
|
gitea_runner_installed_version: >-
|
|
{{
|
|
(gitea_runner_version_cmd.stdout
|
|
| regex_findall('v?([0-9]+\.[0-9]+\.[0-9]+)')
|
|
| first)
|
|
| default('0.0.0')
|
|
}}
|
|
tags: [gitea_runner, update]
|
|
|
|
- name: Determine if update required
|
|
ansible.builtin.set_fact:
|
|
gitea_runner_update_required: "{{ gitea_runner_installed_version != gitea_runner_version }}"
|
|
# Next to the live binary, so the swap is a rename on one filesystem.
|
|
gitea_runner_staged_binary: "{{ gitea_runner_install_dir }}/gitea-runner.new"
|
|
tags: [gitea_runner, update]
|
|
|
|
# Download and verify before anything is stopped: a failed download or checksum leaves the
|
|
# running runner untouched. mortis.kamino._binary_update then stops, backs up, swaps, restarts,
|
|
# checks the version and rolls back on failure, and removes the staged binary.
|
|
- name: Stage and swap in the new runner binary
|
|
when: gitea_runner_update_required
|
|
block:
|
|
# Its own rescue, so that only a staging failure gets this message: a failure in the swap
|
|
# below keeps the rollback message of mortis.kamino._binary_update.
|
|
- name: Stage the new runner binary
|
|
block:
|
|
- name: Download and verify into the staging path
|
|
ansible.builtin.include_tasks: download.yml
|
|
vars:
|
|
gitea_runner_download_dest: "{{ gitea_runner_staged_binary }}"
|
|
tags: [gitea_runner, update]
|
|
rescue:
|
|
- name: Fail the staging
|
|
ansible.builtin.fail:
|
|
msg: >-
|
|
Staging gitea-runner {{ gitea_runner_version }} failed ({{ ansible_failed_result.msg | default('see the task above') }}).
|
|
The runner was not stopped and still runs {{ gitea_runner_installed_version }}.
|
|
tags: [gitea_runner, update]
|
|
|
|
# An include does not pass its tags on to the included tasks, hence apply. Under --check a
|
|
# new unit is only simulated, so the stop and start of the swap would not find it.
|
|
- name: Swap in the staged runner binary
|
|
ansible.builtin.include_role:
|
|
name: mortis.kamino._binary_update
|
|
apply:
|
|
tags: [gitea_runner, update]
|
|
vars:
|
|
_binary_update_service: gitea-runner
|
|
_binary_update_binary_path: "{{ gitea_runner_install_dir }}/gitea-runner"
|
|
_binary_update_staged_path: "{{ gitea_runner_staged_binary }}"
|
|
_binary_update_version_command: ["{{ gitea_runner_install_dir }}/gitea-runner", --version]
|
|
_binary_update_expected_version: "{{ gitea_runner_version }}"
|
|
when: not ansible_check_mode or __gitea_runner_unit_file | default({}) is not changed
|
|
tags: [gitea_runner, update]
|
|
|
|
always:
|
|
# Left behind only when the run failed before the swap; get_url would reuse a matching
|
|
# file anyway, but a stale binary next to the live one is clutter.
|
|
- name: Remove the staged runner binary
|
|
become: true
|
|
ansible.builtin.file:
|
|
path: "{{ gitea_runner_staged_binary }}"
|
|
state: absent
|
|
tags: [gitea_runner, update]
|