Swaps a staged, verified binary into place for a systemd service: refuse when nothing executable is staged, then reload, stop and wait, back up the live binary, rename the staged file over it, start and wait for active, and compare the reported version. A failure after the stop restores this run's backup, starts the service again and fails with a message that says whether the restore and the restart worked. Under --check the waits and the version check are skipped, so a preview against a stopped service does not fall into the rollback. The staged file is removed in every case. The role is internal (ADR 0004 in the environment repository): called only by roles of this Collection by FQCN, outside the public API, marked by the underscore, [INTERNAL] in its meta and argument_specs, and a first task that refuses a call without a parent role. traefik is its first caller and arrives in the same release. Two molecule scenarios use stub binaries under a stub unit, without network: default (successful bump and idempotence, a binary that cannot start, a binary that reports the wrong version, nothing staged, a direct call, a first install) and check_mode (the bump under molecule check against a stopped service changes nothing). Lint: role-name is skipped (its regex rejects the leading underscore, as for prometheus.prometheus roles/_common), meta has no role_name (schema[meta] uses the same regex and cannot be skipped), and .ansible-lint-ignore lists the role's own files for var-naming[no-role-prefix], which strips the underscore from the variable but not from the role name and so cannot pass. The ignore file is kept out of the Collection build and is on the scenario picker's IGNORED list. The README Roadmap no longer lists the role. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01MmzvM9skAvYcph2c9EiPcm
73 lines
3.4 KiB
YAML
73 lines
3.4 KiB
YAML
---
|
|
argument_specs:
|
|
main:
|
|
short_description: "[INTERNAL] Swap a staged binary into place for a systemd service, with rollback"
|
|
description:
|
|
- >-
|
|
[INTERNAL] Called only by roles of this Collection, by its fully qualified name; a direct call from a play
|
|
fails. Not part of the Collection's public API, so its interface can change in any release.
|
|
- >-
|
|
The caller downloads and verifies the new binary and stages it at C(_binary_update_staged_path), on the same
|
|
filesystem as C(_binary_update_binary_path), before it includes this role. The role refuses to stop the
|
|
service when nothing executable is staged.
|
|
- >-
|
|
Then it reloads systemd, stops the service and waits for it to stop, backs up the live binary to
|
|
C(<_binary_update_binary_path>.bak) (when there is one), moves the staged file over the live path, starts the
|
|
service, waits for it to become active and compares the version it reports with
|
|
C(_binary_update_expected_version). On success the backup is removed.
|
|
- >-
|
|
Any failure after the stop restores the backup taken by this run, starts the service again and fails with a
|
|
message that says whether the restore and the restart worked. A failure before the stop leaves the service
|
|
running and does not restart it. The staged file is removed in every case.
|
|
- >-
|
|
Under C(--check) the role skips the waits and the version check, so a preview against a stopped service does
|
|
not report a rollback. The stop, backup and start report what they would change.
|
|
options:
|
|
_binary_update_service:
|
|
type: str
|
|
required: true
|
|
description:
|
|
- Name of the systemd unit that runs the binary.
|
|
_binary_update_binary_path:
|
|
type: path
|
|
required: true
|
|
description:
|
|
- Path of the live binary that the unit runs.
|
|
_binary_update_staged_path:
|
|
type: path
|
|
required: true
|
|
description:
|
|
- >-
|
|
Downloaded and verified new binary, executable, on the same filesystem as C(_binary_update_binary_path) so
|
|
that the swap is a rename. Removed by the role whether the update succeeds or fails.
|
|
_binary_update_version_command:
|
|
type: list
|
|
elements: str
|
|
required: true
|
|
description:
|
|
- >-
|
|
Command, as an argument list, whose output holds the version of the binary at
|
|
C(_binary_update_binary_path), for example C([/usr/local/bin/traefik, version]).
|
|
_binary_update_expected_version:
|
|
type: str
|
|
required: true
|
|
description:
|
|
- Version the new binary must report. A leading C(v) is ignored.
|
|
_binary_update_version_regex:
|
|
type: str
|
|
default: 'v?([0-9]+\.[0-9]+\.[0-9]+)'
|
|
description:
|
|
- >-
|
|
Regular expression with one capture group, the version without a leading C(v). Its first match in the
|
|
output of C(_binary_update_version_command) is compared with C(_binary_update_expected_version).
|
|
_binary_update_stop_timeout:
|
|
type: int
|
|
default: 60
|
|
description:
|
|
- Seconds to wait for the service to stop. It is checked every 2 seconds.
|
|
_binary_update_start_timeout:
|
|
type: int
|
|
default: 30
|
|
description:
|
|
- Seconds to wait for the service to become active after a start, also after a rollback. It is checked every 2 seconds.
|