Files
Kamino/roles/gitea/tasks/update.yml
T
Defame1297andClaude Opus 5.5 f060461152
Build / build (pull_request) Successful in 12s
Lint / lint (pull_request) Failing after 43s
Molecule / molecule (pull_request) Successful in 1m20s
feat(gitea): add the gitea role
Moves the gitea role from the environment repository, the second wave 2 role and the
second caller of the internal _binary_update role.

Against the source:
- The update path stages the downloaded, signature-verified binary in a directory next to
  the live one and hands the stop, backup, swap, restart, version check and rollback to
  mortis.kamino._binary_update (include_role with apply tags, so --tags update reaches
  it). A download or signature failure still leaves the running service untouched and
  says so; a failure in the swap keeps the rollback message of _binary_update. Its default
  version regex is the one the source used.
- The same two small behaviour changes as for traefik come with _binary_update: the backup
  is taken whenever a live binary exists, and a failure before the stop no longer
  restarts the running service.
- The update no longer removes a PID file between the stop and the start, and
  gitea_pid_file is gone: the unit runs `gitea web` without --pid and has no PIDFile=,
  so Gitea writes no PID file and systemd reads none.
- The database-migration warning of the source's rollback message (the previous binary
  may refuse a migrated schema) moves to the gitea_update docs in the README and the
  argument_specs, since _binary_update owns the failure message.
- The legacy name guard (pre-rename variables of the environment) is dropped, as in the
  wave 1 roles, and the argument_specs and README no longer mention it. The jwt secret,
  mailer and e-mail confirmation asserts stay.
- Environment references are gone from comments, app.ini.j2, the README and the
  argument_specs: issue numbers, decision records, host names, inventory paths,
  playbooks, the network and proxy layout and other roles' copies of the paths. The
  Renovate comment on gitea_version is dropped; the README and argument_specs recommend
  pinning the version in inventory. The mint messages no longer name a playbook.
- On a fresh host the token assert and the SSH-key upload ran before the unit was
  written and Gitea started, so a first install could never complete. Both now run after
  the service check, and the upload first waits (up to 60 s, not under --check) for the
  local listener; the listener address is resolved once for both.
- REVERSE_PROXY_LIMIT, hard-coded to 2, is now gitea_reverse_proxy_limit with default 1:
  a limit above the real number of proxies lets a client forge the address Gitea logs and
  Fail2Ban bans. A setup with two proxies sets it to 2.
- The gitea commands with user-supplied values (migrate, admin user list and create, and
  the token mint) take argv instead of a command string; still run through sudo -u.
- gitea_version is asserted at role start to be a plain X.Y.Z, with no leading v.
- meta namespace mortis; the scenario follows the Kamino conventions (header,
  test_sequence, no provisioner env) and calls the role by FQCN, also in the child
  ansible-playbook of the mint CI-guard cases. Coverage is unchanged.

No other default changed; DISABLE_REGISTRATION stays hard-coded to true.

Changelog fragment, README Roadmap and the CLAUDE.md role list updated.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01MmzvM9skAvYcph2c9EiPcm
2026-11-21 21:53:20 +00:00

88 lines
3.5 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.
- 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 }}"
tags: [gitea, update]
always:
- name: Remove the Gitea staging directory
become: true
ansible.builtin.file:
path: "{{ gitea_staging_dir }}"
state: absent
tags: [gitea, update]