molecule's trailing destroy runs the Docker driver's destroy playbook, whose "Wait for instance(s) deletion to complete" task alone costs about 5.6 s per scenario, about 84 s over the 15 scenarios of a full run. The whole destroy phase measured about 103 s per full run (the median across full runs, among them 4764, 4714, 4698 and 4578). The workflow already removes stale containers before the run, so it can remove each scenario's containers itself with `docker rm -f` as soon as the scenario ends, pass or fail, and skip the playbook. The names come from each scenario's molecule.yml (platforms[].name) via the molecule venv's Python and PyYAML, so no list is kept in the workflow. A failed removal fails the step. The test_sequence rule in the workflow guidance now says both destroys are left out and that platform names are literal. Assisted-by: Claude Code:claude-opus-5-5
_binary_update
Internal role. It is called only by other roles of this Collection and is not part of the Collection's public API: its interface can change in any release, without a major version. Do not call it from a play; it refuses to run without a parent role.
It swaps a new binary into place for a systemd service and rolls back when the update fails. The calling role does the download and the verification (a checksum, a signature, a checksum file: each upstream differs) and stages the verified file next to the live binary before it includes this role, so a slow or failed download never stops the service.
Variables and their types are defined in meta/argument_specs.yml,
which is the source of truth.
What it does
- Refuses to continue, with the service untouched, when nothing executable is staged.
- Reloads systemd, stops the service and waits until it has stopped.
- Copies the live binary to
<binary>.bak, when there is one. - Moves the staged file over the live binary: one rename on one filesystem, so the live path never holds a partial file.
- Starts the service, waits until it is active and compares the version the new binary reports with the expected version.
- Removes the backup.
Any failure after the stop restores the backup of this run, starts the service again and fails
with a message that says whether the restore and the restart worked. The staged file is removed
in every case. A .bak left by an earlier run is never restored, only replaced.
Under --check the waits and the version check are skipped, so a preview against a stopped
service does not report a rollback; the stop, the backup and the start report what they would
change (for a running service with a live binary: all three).
Limits:
- The backup keeps the owner, group and mode of the live binary, but nothing else (no extended attributes or file capabilities).
- Only one backup is kept. When a restore fails, restore
<binary>.bakby hand before the next run: that run replaces it. - "Active" is checked once the unit reports it. A
Type=simpleservice that crashes a moment after it started passes the wait and is caught only by the version check, if at all.
Calling it
- name: Swap in the new binary
ansible.builtin.include_role:
name: mortis.kamino._binary_update
apply:
tags: [myservice, update]
vars:
_binary_update_service: myservice
_binary_update_binary_path: /usr/local/bin/myservice
_binary_update_staged_path: /usr/local/bin/myservice.new
_binary_update_version_command: [/usr/local/bin/myservice, --version]
_binary_update_expected_version: "{{ myservice_version }}"
tags: [myservice, update]
An include does not pass its tags on to the included tasks, so pass them with apply as well.
Compare the installed version first and stage and include only when it differs; the role
itself always stops and starts the service.
Testing
Two molecule scenarios run against stub binaries (shell scripts) under a stub unit, with no
network: default covers a successful bump, its idempotence, a binary that cannot start, a
binary that reports another version (both rolled back), a run with nothing staged (the service
is not stopped), a direct call from a play (refused) and a first install with nothing to back
up. check_mode runs the bump under --check against a stopped service and checks that
nothing changed. The calling roles' own scenarios cover a real upstream binary.