# _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`](meta/argument_specs.yml), which is the source of truth. ## What it does 1. Refuses to continue, with the service untouched, when nothing executable is staged. 2. Reloads systemd, stops the service and waits until it has stopped. 3. Copies the live binary to `.bak`, when there is one. 4. Moves the staged file over the live binary: one rename on one filesystem, so the live path never holds a partial file. 5. Starts the service, waits until it is active and compares the version the new binary reports with the expected version. 6. 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 `.bak` by hand before the next run: that run replaces it. - "Active" is checked once the unit reports it. A `Type=simple` service that crashes a moment after it started passes the wait and is caught only by the version check, if at all. ## Calling it ```yaml - 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.