--- # Shared by the scenarios. Stub "binaries" are shell scripts: `version` prints a version, `check` # is the unit's ExecStartPre, `serve` is the long-running process. The unit only becomes active # when `check` succeeds, so a binary that cannot start fails deterministically instead of being # active for a moment before it exits. - name: Prepare hosts: all gather_facts: false tasks: - name: Create the stub directory ansible.builtin.file: path: /opt/stubs state: directory mode: "0755" - name: Write the stub binaries ansible.builtin.copy: dest: "/opt/stubs/stubd-{{ stub.name }}" mode: "0755" content: | #!/bin/sh case "$1" in version) echo "stubd version v{{ stub.reports }}" ;; check) exit {{ stub.check_rc }} ;; serve) exec sleep infinity ;; *) exit 2 ;; esac loop: - {name: 1.0.0, reports: 1.0.0, check_rc: 0} - {name: 2.0.0, reports: 2.0.0, check_rc: 0} # cannot start: the rollback test - {name: 3.0.0-broken, reports: 3.0.0, check_rc: 1} # starts but reports another version: the version check test - {name: 3.0.0-mislabelled, reports: 9.9.9, check_rc: 0} loop_control: loop_var: stub label: "{{ stub.name }}" - name: Install stub 1.0.0 as the live binary ansible.builtin.copy: src: /opt/stubs/stubd-1.0.0 dest: /usr/local/bin/stubd remote_src: true mode: "0755" - name: Write the stub unit ansible.builtin.copy: dest: /etc/systemd/system/stubd.service mode: "0644" content: | [Unit] Description=Stub service for the _binary_update scenarios [Service] ExecStartPre=/usr/local/bin/stubd check ExecStart=/usr/local/bin/stubd serve [Install] WantedBy=multi-user.target - name: Start the stub service ansible.builtin.systemd: name: stubd state: started enabled: true daemon_reload: true