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
90 lines
3.6 KiB
YAML
90 lines
3.6 KiB
YAML
---
|
|
- name: Check installed Gitea version
|
|
ansible.builtin.command: "{{ gitea_install_dir }}/gitea --version"
|
|
register: gitea_version_cmd
|
|
changed_when: false
|
|
# Failure is expected before the first install (binary 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, update]
|
|
|
|
- name: Extract installed Gitea version
|
|
ansible.builtin.set_fact:
|
|
gitea_installed_version: >-
|
|
{{
|
|
(gitea_version_cmd.stdout
|
|
| regex_findall('v?([0-9]+\.[0-9]+\.[0-9]+)')
|
|
| first)
|
|
| default('0.0.0')
|
|
}}
|
|
tags: [gitea, update]
|
|
|
|
- name: Determine if Gitea update required
|
|
ansible.builtin.set_fact:
|
|
gitea_update_required: "{{ gitea_installed_version != gitea_version }}"
|
|
# Next to the live binary, so the swap is a rename on one filesystem.
|
|
gitea_staging_dir: "{{ gitea_install_dir }}/.gitea-staging"
|
|
tags: [gitea, update]
|
|
|
|
# Download and verify before anything is stopped: a failed download or signature check leaves
|
|
# the running Gitea untouched. mortis.kamino._binary_update then stops, backs up, swaps,
|
|
# restarts, checks the version and rolls back on failure, and removes the staged binary.
|
|
# The rollback restores the binary only: Gitea migrates its database when the new version
|
|
# starts, so after a failure past that point the previous binary may refuse the newer schema.
|
|
- name: Stage and swap in the new Gitea binary
|
|
when: gitea_update_required
|
|
block:
|
|
- name: Create the Gitea staging directory
|
|
become: true
|
|
ansible.builtin.file:
|
|
path: "{{ gitea_staging_dir }}"
|
|
state: directory
|
|
owner: root
|
|
group: root
|
|
mode: "0700"
|
|
tags: [gitea, update]
|
|
|
|
# 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 Gitea binary
|
|
block:
|
|
- name: Download and verify into the staging directory
|
|
ansible.builtin.include_tasks: download.yml
|
|
vars:
|
|
gitea_download_dest: "{{ gitea_staging_dir }}/gitea"
|
|
tags: [gitea, update]
|
|
rescue:
|
|
- name: Fail the staging
|
|
ansible.builtin.fail:
|
|
msg: >-
|
|
Staging Gitea {{ gitea_version }} failed ({{ ansible_failed_result.msg | default('see the task above') }}).
|
|
Gitea was not stopped and still runs {{ gitea_installed_version }}.
|
|
tags: [gitea, 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 Gitea binary
|
|
ansible.builtin.include_role:
|
|
name: mortis.kamino._binary_update
|
|
apply:
|
|
tags: [gitea, update]
|
|
vars:
|
|
_binary_update_service: gitea
|
|
_binary_update_binary_path: "{{ gitea_install_dir }}/gitea"
|
|
_binary_update_staged_path: "{{ gitea_staging_dir }}/gitea"
|
|
_binary_update_version_command: ["{{ gitea_install_dir }}/gitea", --version]
|
|
_binary_update_expected_version: "{{ gitea_version }}"
|
|
when: not ansible_check_mode or __gitea_unit_file | default({}) is not changed
|
|
tags: [gitea, update]
|
|
|
|
always:
|
|
- name: Remove the Gitea staging directory
|
|
become: true
|
|
ansible.builtin.file:
|
|
path: "{{ gitea_staging_dir }}"
|
|
state: absent
|
|
tags: [gitea, update]
|