--- # 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