Copied from the maintainer's local role and reworked for the Collection: the binary swap and rollback of an update go through the internal _binary_update role, input checks move to tasks/validate.yml, the removal ends the role, commands take argv, and the molecule tooling needs an explicit collections requirements file. Adds a molecule scenario with stub Docker, runner and release files. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01MmzvM9skAvYcph2c9EiPcm
86 lines
3.2 KiB
YAML
86 lines
3.2 KiB
YAML
---
|
|
# Stand-ins for what the scenario cannot have: a Docker daemon (the runner unit requires
|
|
# docker.service), an installed and registered runner (so the role skips the Docker install and
|
|
# the registration, which need Docker Hub and a Gitea server), and the release files of two
|
|
# newer versions behind file:// URLs. 6.0.1 has a matching checksum file, 6.0.2 a wrong one.
|
|
# The stub binary answers --version and, for `daemon`, sleeps like a running service.
|
|
- name: Prepare
|
|
hosts: all
|
|
gather_facts: false
|
|
tasks:
|
|
- name: Write a stub docker.service
|
|
ansible.builtin.copy:
|
|
dest: /etc/systemd/system/docker.service
|
|
mode: "0644"
|
|
content: |
|
|
[Unit]
|
|
Description=Docker stub for molecule
|
|
[Service]
|
|
Type=oneshot
|
|
ExecStart=/bin/true
|
|
RemainAfterExit=yes
|
|
[Install]
|
|
WantedBy=multi-user.target
|
|
|
|
- name: Start the stub docker.service
|
|
ansible.builtin.systemd:
|
|
name: docker
|
|
state: started
|
|
daemon_reload: true
|
|
|
|
- name: Create the download directory
|
|
ansible.builtin.file:
|
|
path: /opt/molecule-download
|
|
state: directory
|
|
mode: "0755"
|
|
|
|
- name: Write the installed stub runner and the release files
|
|
ansible.builtin.copy:
|
|
dest: "{{ gitea_runner_test_stub.dest }}"
|
|
mode: "0755"
|
|
content: |
|
|
#!/bin/sh
|
|
case "$1" in
|
|
--version) echo "gitea-runner version v{{ gitea_runner_test_stub.version }}" ;;
|
|
daemon) exec sleep infinity ;;
|
|
*) echo "stub runner: unexpected arguments: $*" >&2; exit 2 ;;
|
|
esac
|
|
loop:
|
|
- {dest: /usr/local/bin/gitea-runner, version: 6.0.0}
|
|
- {dest: /opt/molecule-download/gitea-runner-6.0.1-linux-amd64, version: 6.0.1}
|
|
- {dest: /opt/molecule-download/gitea-runner-6.0.2-linux-amd64, version: 6.0.2}
|
|
loop_control:
|
|
loop_var: gitea_runner_test_stub
|
|
label: "{{ gitea_runner_test_stub.dest }}"
|
|
|
|
- name: Hash the 6.0.1 release file
|
|
ansible.builtin.stat:
|
|
path: /opt/molecule-download/gitea-runner-6.0.1-linux-amd64
|
|
checksum_algorithm: sha256
|
|
register: gitea_runner_test_release
|
|
|
|
- name: Write the checksum files, the 6.0.2 one wrong
|
|
ansible.builtin.copy:
|
|
dest: "/opt/molecule-download/gitea-runner-{{ gitea_runner_test_sum.version }}-linux-amd64.sha256"
|
|
mode: "0644"
|
|
content: "{{ gitea_runner_test_sum.sum }} gitea-runner-{{ gitea_runner_test_sum.version }}-linux-amd64\n"
|
|
loop:
|
|
- {version: 6.0.1, sum: "{{ gitea_runner_test_release.stat.checksum }}"}
|
|
- {version: 6.0.2, sum: "{{ '0' * 64 }}"}
|
|
loop_control:
|
|
loop_var: gitea_runner_test_sum
|
|
label: "{{ gitea_runner_test_sum.version }}"
|
|
|
|
# Mode 0644 on purpose: configure must tighten it to 0600.
|
|
- name: Create the work directory with a stand-in registration
|
|
ansible.builtin.file:
|
|
path: /var/lib/gitea-runner
|
|
state: directory
|
|
mode: "0750"
|
|
|
|
- name: Write the stand-in registration
|
|
ansible.builtin.copy:
|
|
dest: /var/lib/gitea-runner/.runner
|
|
mode: "0644"
|
|
content: '{"molecule": "not a registration"}'
|