Adds _binary_update, the internal role that service roles will use to swap in a new binary with rollback. Its first caller, traefik, comes in the next pull request, and both ship in the same release.
What it does
The caller downloads and verifies the new binary and stages it next to the live one before it includes this role. The role then:
refuses to stop the service when nothing executable is staged;
reloads systemd, stops the service and waits for it to stop;
backs up the live binary, keeping its owner, group and mode;
swaps the staged file in with one mv, so the live path never holds a partial file;
starts the service and waits for it to become active;
checks the version the new binary reports;
removes the backup.
On failure. Any failure after the stop restores this run's backup, starts the service again and fails with a message that names the failing task and 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 always removed. A failure to remove the backup after a successful update does not roll the update back.
Under --check. The waits and the version check are skipped, so a preview against a stopped service does not report a rollback.
Marked internal
The underscore prefix in the name.
[INTERNAL] in the meta and in argument_specs.
A first task that refuses a call without a parent role.
The README says the interface can change in any release.
Lint
role-name is skipped in .ansible-lint. Its regex rejects a leading underscore. prometheus.prometheus does the same for roles/_common.
meta/main.yml has no role_name.schema[meta] applies the same regex and cannot be skipped.
.ansible-lint-ignore lists only this role's own files for var-naming[no-role-prefix]. That rule strips the leading underscore from the variable name but not from the role name (var_naming.py:185-186), so no name can pass. A caller's FQCN include_role vars are not checked against that prefix, so the callers need no entry.
The ignore file stays out of the Collection. It is in galaxy.ymlbuild_ignore, which test_check_tarball enforces, and on the scenario picker's IGNORED list.
Tests (molecule, no network)
Both scenarios use stub "binaries" (shell scripts) under a stub systemd unit. The unit's ExecStartPre makes a binary that cannot start fail deterministically.
default:
a successful bump and its idempotence;
a binary that cannot start, which is restored;
a binary that reports another version, which is restored;
nothing staged: the service is not stopped and its MainPID is unchanged;
a direct call from a play, which is refused;
a first install with nothing to back up.
check_mode: the bump runs under molecule's check step against a stopped service. Nothing changes and no rollback is reported.
The test caller role lives in molecule/resources/roles, because the role refuses a call from a play.
Verified
tests/scripts passes, including #264's rule that roles call each other by their full name.
All pre-commit hooks pass.
--syntax-check passes on every scenario playbook.
The test_sequence lists parse as intended.
An independent subagent review ran in two rounds. Its first round found a blocker: two test_sequence lines were merged, so verify would never have run. It also found these should-fixes:
removing the backup could roll back a successful update;
a timed-out wait gave no cause;
the rollback restarted a service that was never stopped;
the backup lost its owner and group.
All of them are fixed, and the second round confirmed the fixes.
Not verified
Both scenarios. This pull request's molecule run is their first execution.
The README's documented limits:
Only one backup is kept, so after a failed restore you have to restore .bak by hand before the next run.
A Type=simple service that crashes a moment after it starts passes the wait.
Adds `_binary_update`, the internal role that service roles will use to swap in a new binary with rollback. Its first caller, `traefik`, comes in the next pull request, and both ship in the same release.
## What it does
The caller downloads and verifies the new binary and stages it next to the live one before it includes this role. The role then:
- refuses to stop the service when nothing executable is staged;
- reloads systemd, stops the service and waits for it to stop;
- backs up the live binary, keeping its owner, group and mode;
- swaps the staged file in with one `mv`, so the live path never holds a partial file;
- starts the service and waits for it to become active;
- checks the version the new binary reports;
- removes the backup.
**On failure.** Any failure after the stop restores this run's backup, starts the service again and fails with a message that names the failing task and 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 always removed. A failure to remove the backup after a successful update does not roll the update back.
**Under `--check`.** The waits and the version check are skipped, so a preview against a stopped service does not report a rollback.
## Marked internal
- The underscore prefix in the name.
- `[INTERNAL]` in the meta and in `argument_specs`.
- A first task that refuses a call without a parent role.
- The README says the interface can change in any release.
## Lint
- **`role-name` is skipped in `.ansible-lint`.** Its regex rejects a leading underscore. prometheus.prometheus does the same for `roles/_common`.
- **`meta/main.yml` has no `role_name`.** `schema[meta]` applies the same regex and cannot be skipped.
- **`.ansible-lint-ignore` lists only this role's own files for `var-naming[no-role-prefix]`.** That rule strips the leading underscore from the variable name but not from the role name (`var_naming.py:185-186`), so no name can pass. A caller's FQCN `include_role` vars are not checked against that prefix, so the callers need no entry.
- **The ignore file stays out of the Collection.** It is in `galaxy.yml` `build_ignore`, which `test_check_tarball` enforces, and on the scenario picker's `IGNORED` list.
## Tests (molecule, no network)
Both scenarios use stub "binaries" (shell scripts) under a stub systemd unit. The unit's `ExecStartPre` makes a binary that cannot start fail deterministically.
**`default`:**
- a successful bump and its idempotence;
- a binary that cannot start, which is restored;
- a binary that reports another version, which is restored;
- nothing staged: the service is not stopped and its MainPID is unchanged;
- a direct call from a play, which is refused;
- a first install with nothing to back up.
**`check_mode`:** the bump runs under molecule's `check` step against a stopped service. Nothing changes and no rollback is reported.
The test caller role lives in `molecule/resources/roles`, because the role refuses a call from a play.
## Verified
- `tests/scripts` passes, including #264's rule that roles call each other by their full name.
- All pre-commit hooks pass.
- `--syntax-check` passes on every scenario playbook.
- The `test_sequence` lists parse as intended.
- An independent subagent review ran in two rounds. Its first round found a blocker: two `test_sequence` lines were merged, so `verify` would never have run. It also found these should-fixes:
- removing the backup could roll back a successful update;
- a timed-out wait gave no cause;
- the rollback restarted a service that was never stopped;
- the backup lost its owner and group.
All of them are fixed, and the second round confirmed the fixes.
## Not verified
- **Both scenarios.** This pull request's molecule run is their first execution.
- **The README's documented limits:**
- Only one backup is kept, so after a failed restore you have to restore `.bak` by hand before the next run.
- A `Type=simple` service that crashes a moment after it starts passes the wait.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
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
Defame1297
scheduled this pull request to auto merge when all checks succeed 2026-11-20 19:06:31 +00:00
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Adds
_binary_update, the internal role that service roles will use to swap in a new binary with rollback. Its first caller,traefik, comes in the next pull request, and both ship in the same release.What it does
The caller downloads and verifies the new binary and stages it next to the live one before it includes this role. The role then:
mv, so the live path never holds a partial file;On failure. Any failure after the stop restores this run's backup, starts the service again and fails with a message that names the failing task and 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 always removed. A failure to remove the backup after a successful update does not roll the update back.
Under
--check. The waits and the version check are skipped, so a preview against a stopped service does not report a rollback.Marked internal
[INTERNAL]in the meta and inargument_specs.Lint
role-nameis skipped in.ansible-lint. Its regex rejects a leading underscore. prometheus.prometheus does the same forroles/_common.meta/main.ymlhas norole_name.schema[meta]applies the same regex and cannot be skipped..ansible-lint-ignorelists only this role's own files forvar-naming[no-role-prefix]. That rule strips the leading underscore from the variable name but not from the role name (var_naming.py:185-186), so no name can pass. A caller's FQCNinclude_rolevars are not checked against that prefix, so the callers need no entry.galaxy.ymlbuild_ignore, whichtest_check_tarballenforces, and on the scenario picker'sIGNOREDlist.Tests (molecule, no network)
Both scenarios use stub "binaries" (shell scripts) under a stub systemd unit. The unit's
ExecStartPremakes a binary that cannot start fail deterministically.default:check_mode: the bump runs under molecule'scheckstep against a stopped service. Nothing changes and no rollback is reported.The test caller role lives in
molecule/resources/roles, because the role refuses a call from a play.Verified
tests/scriptspasses, including #264's rule that roles call each other by their full name.All pre-commit hooks pass.
--syntax-checkpasses on every scenario playbook.The
test_sequencelists parse as intended.An independent subagent review ran in two rounds. Its first round found a blocker: two
test_sequencelines were merged, soverifywould never have run. It also found these should-fixes:All of them are fixed, and the second round confirmed the fixes.
Not verified
.bakby hand before the next run.Type=simpleservice that crashes a moment after it starts passes the wait.🤖 Generated with Claude Code