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
170 lines
5.9 KiB
YAML
170 lines
5.9 KiB
YAML
---
|
|
# Converge left stub 2.0.0 running. Each failure case below runs after the one before it and
|
|
# expects to find 2.0.0 running again: a case that broke the rollback breaks the next one too.
|
|
- name: Verify the successful bump
|
|
hosts: all
|
|
gather_facts: false
|
|
tasks:
|
|
- name: Check the state after converge
|
|
ansible.builtin.include_tasks: tasks/assert_state.yml
|
|
vars:
|
|
verify_case: converge
|
|
verify_version: 2.0.0
|
|
|
|
- name: Verify that a binary that cannot start is rolled back
|
|
hosts: all
|
|
gather_facts: false
|
|
tasks:
|
|
- name: Update to a stub whose unit cannot start
|
|
block:
|
|
- name: Run the update
|
|
ansible.builtin.include_role:
|
|
name: binary_update_caller
|
|
vars:
|
|
binary_update_caller_version: 3.0.0
|
|
binary_update_caller_stage: 3.0.0-broken
|
|
- name: The update should have failed
|
|
ansible.builtin.fail:
|
|
msg: The update to a stub that cannot start succeeded.
|
|
rescue:
|
|
- name: The failure says the backup was restored and the service is active
|
|
ansible.builtin.assert:
|
|
that:
|
|
- ansible_failed_result.msg is search('Restored the previous binary')
|
|
- ansible_failed_result.msg is search('stubd was started again and is active')
|
|
# the failing ExecStartPre fails the start job itself, so the restart task fails
|
|
- ansible_failed_result.msg is search('failed at Start the service:')
|
|
fail_msg: "{{ ansible_failed_result.msg }}"
|
|
quiet: true
|
|
|
|
- name: Check the state after the rollback
|
|
ansible.builtin.include_tasks: tasks/assert_state.yml
|
|
vars:
|
|
verify_case: broken binary
|
|
verify_version: 2.0.0
|
|
|
|
- name: Verify that a binary reporting another version is rolled back
|
|
hosts: all
|
|
gather_facts: false
|
|
tasks:
|
|
- name: Update to a stub that reports the wrong version
|
|
block:
|
|
- name: Run the update
|
|
ansible.builtin.include_role:
|
|
name: binary_update_caller
|
|
vars:
|
|
binary_update_caller_version: 3.0.0
|
|
binary_update_caller_stage: 3.0.0-mislabelled
|
|
- name: The update should have failed
|
|
ansible.builtin.fail:
|
|
msg: The update to a mislabelled stub succeeded.
|
|
rescue:
|
|
- name: The failure names the version mismatch and the restore
|
|
ansible.builtin.assert:
|
|
that:
|
|
- ansible_failed_result.msg is search('reports 9\.9\.9, expected 3\.0\.0')
|
|
- ansible_failed_result.msg is search('Restored the previous binary')
|
|
- ansible_failed_result.msg is search('is active')
|
|
fail_msg: "{{ ansible_failed_result.msg }}"
|
|
quiet: true
|
|
|
|
- name: Check the state after the rollback
|
|
ansible.builtin.include_tasks: tasks/assert_state.yml
|
|
vars:
|
|
verify_case: wrong version
|
|
verify_version: 2.0.0
|
|
|
|
- name: Verify that nothing is stopped when nothing was staged
|
|
hosts: all
|
|
gather_facts: false
|
|
tasks:
|
|
- name: Read the unit before the attempt
|
|
ansible.builtin.systemd:
|
|
name: stubd
|
|
register: verify_unit_before
|
|
|
|
- name: Update without staging a binary
|
|
block:
|
|
- name: Run the update
|
|
ansible.builtin.include_role:
|
|
name: binary_update_caller
|
|
vars:
|
|
binary_update_caller_version: 3.0.0
|
|
binary_update_caller_stage: ""
|
|
- name: The update should have failed
|
|
ansible.builtin.fail:
|
|
msg: The update without a staged binary succeeded.
|
|
rescue:
|
|
- name: The failure says the service was not stopped
|
|
ansible.builtin.assert:
|
|
that: ansible_failed_result.msg is search('was not stopped')
|
|
fail_msg: "{{ ansible_failed_result.msg }}"
|
|
quiet: true
|
|
|
|
- name: Read the unit after the attempt
|
|
ansible.builtin.systemd:
|
|
name: stubd
|
|
register: verify_unit_after
|
|
|
|
- name: The service kept running the same process
|
|
ansible.builtin.assert:
|
|
that: verify_unit_after.status.MainPID == verify_unit_before.status.MainPID
|
|
quiet: true
|
|
|
|
- name: Check the state after the refusal
|
|
ansible.builtin.include_tasks: tasks/assert_state.yml
|
|
vars:
|
|
verify_case: nothing staged
|
|
verify_version: 2.0.0
|
|
|
|
- name: Verify that a play cannot call the role directly
|
|
hosts: all
|
|
gather_facts: false
|
|
tasks:
|
|
- name: Call the role from a play
|
|
block:
|
|
- name: Include the internal role without a parent role
|
|
ansible.builtin.include_role:
|
|
name: mortis.kamino._binary_update
|
|
vars:
|
|
_binary_update_service: stubd
|
|
_binary_update_binary_path: /usr/local/bin/stubd
|
|
_binary_update_staged_path: /usr/local/bin/stubd.new
|
|
_binary_update_version_command: [/usr/local/bin/stubd, version]
|
|
_binary_update_expected_version: 2.0.0
|
|
- name: The direct call should have failed
|
|
ansible.builtin.fail:
|
|
msg: A play called the internal role.
|
|
rescue:
|
|
- name: The failure says the role is internal
|
|
ansible.builtin.assert:
|
|
that: ansible_failed_result.msg is search('is internal')
|
|
fail_msg: "{{ ansible_failed_result.msg }}"
|
|
quiet: true
|
|
|
|
- name: Verify a first install, with no live binary to back up
|
|
hosts: all
|
|
gather_facts: false
|
|
tasks:
|
|
- name: Stop the stub service
|
|
ansible.builtin.systemd:
|
|
name: stubd
|
|
state: stopped
|
|
|
|
- name: Remove the live binary
|
|
ansible.builtin.file:
|
|
path: /usr/local/bin/stubd
|
|
state: absent
|
|
|
|
- name: Install stub 2.0.0
|
|
ansible.builtin.include_role:
|
|
name: binary_update_caller
|
|
vars:
|
|
binary_update_caller_version: 2.0.0
|
|
|
|
- name: Check the state after the first install
|
|
ansible.builtin.include_tasks: tasks/assert_state.yml
|
|
vars:
|
|
verify_case: first install
|
|
verify_version: 2.0.0
|