From 12c70ec7dc1382ad524aa645089c2f4119ebbe70 Mon Sep 17 00:00:00 2001 From: Claude Code AI - Gitea MCP <3+claude@noreply.git.rkdr.net> Date: Sun, 25 Oct 2026 12:11:18 +0000 Subject: [PATCH 1/4] feat(molecule): add the molecule workflow and an image smoke scenario .gitea/workflows/molecule.yml runs every molecule scenario of the Collection on the kamino-molecule host-executor label of kamino-runner (the Docker daemon of the runner LXC, no job container, no Docker socket handed out), against the molecule-ubuntu2404 image pinned by tag and digest. Scenarios are discovered: extensions/molecule/*/ and roles/*/molecule/*/, so the wave-1 roles only add their scenario directory. extensions/molecule/image-smoke tests the image itself: Ubuntu 24.04, systemd as PID 1 and reachable over the container connection, the packages the roles manage, ssh enabled, the python bindings Ansible needs, NET_ADMIN. A rebuilt or re-pinned image therefore has to pass before a role scenario trusts it. Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01MmzvM9skAvYcph2c9EiPcm --- .gitea/workflows/molecule.yml | 117 +++++++++++++++++++ extensions/molecule/image-smoke/converge.yml | 7 ++ extensions/molecule/image-smoke/molecule.yml | 27 +++++ extensions/molecule/image-smoke/verify.yml | 58 +++++++++ 4 files changed, 209 insertions(+) create mode 100644 .gitea/workflows/molecule.yml create mode 100644 extensions/molecule/image-smoke/converge.yml create mode 100644 extensions/molecule/image-smoke/molecule.yml create mode 100644 extensions/molecule/image-smoke/verify.yml diff --git a/.gitea/workflows/molecule.yml b/.gitea/workflows/molecule.yml new file mode 100644 index 0000000..e2a8c3f --- /dev/null +++ b/.gitea/workflows/molecule.yml @@ -0,0 +1,117 @@ +name: Molecule + +# Behavioural tests of the Collection: every molecule scenario under +# extensions/molecule/*/ and roles/*/molecule/*/. extensions/molecule/image-smoke +# tests the test image itself, so it runs even before any role exists. +# +# It runs on the `kamino-molecule` label, a host executor on kamino-runner, which uses +# that LXC's own Docker daemon; no job container is given the Docker socket. That makes +# the job root-equivalent on the runner LXC, which is rebuildable and holds no +# production secret (ADR 0004, Runner isolation). The runner's firewall is inert until +# the Proxmox datacenter firewall is enabled, so a scenario can reach the whole LAN: +# keep mortis/kamino private and accepting no fork pull requests until then. The `if:` +# guard is a convenience filter, not a boundary: the workflow file comes from the PR +# head. The real condition is that only trusted people can push branches here. +# +# Tooling is provisioned on the runner by the gitea_runner role (molecule venv and the +# collections the roles use); this job installs nothing. The test image is pulled from +# the registry by tag and digest (the digest is what is enforced). Bump both here when +# image.yml publishes a new molecule-ubuntu2404 version. +on: # yamllint disable-line rule:truthy + pull_request: + branches: + - main + paths: &paths + - 'roles/**' + - 'extensions/**' + - 'plugins/**' + - 'meta/**' + - 'galaxy.yml' + - '.gitea/workflows/molecule.yml' + push: + branches: + - main + paths: *paths + workflow_dispatch: {} + +permissions: + contents: read + +# Scenarios use fixed container names on the runner's shared Docker daemon. +concurrency: + group: molecule + cancel-in-progress: false + +jobs: + molecule: + # Same-repo, non-bot branches only; a push to main or a manual dispatch always runs. + if: >- + github.repository == 'mortis/kamino' && + (github.event_name != 'pull_request' || + (github.event.pull_request.head.repo.full_name == github.repository && + !startsWith(github.head_ref, 'renovate/'))) + runs-on: [kamino-molecule] + timeout-minutes: 30 + env: + MOLECULE_VENV: /opt/molecule-venv + MOLECULE_COLLECTIONS: /opt/molecule-collections + # Used by the scenarios as `image: ${MOLECULE_IMAGE}`; set it the same way to run + # one locally. + MOLECULE_IMAGE: git.rkdr.net/mortis/molecule-ubuntu2404:0.1.0@sha256:80dbfa7f88309072e954ae20e80ee8171bd750abc7c1d9563c746bf6f0121f04 + steps: + # Provisioned by the gitea_runner role (install_services); fail with a clear + # message when this runs before it has. + - name: Check the provisioned tooling + run: | + test -x "$MOLECULE_VENV/bin/molecule" || { echo "::error::molecule is not installed on this runner: run install_services for kamino-runner first"; exit 1; } + docker version --format '{{.Server.Version}}' || { echo "::error::the Docker daemon is not reachable by the runner user"; exit 1; } + + # The Collection must sit at ansible_collections/mortis/kamino for FQCNs to resolve. + - name: Checkout the commit under test + env: + GIT_CONFIG_COUNT: "1" + GIT_CONFIG_KEY_0: http.extraheader + GIT_CONFIG_VALUE_0: "AUTHORIZATION: bearer ${{ secrets.GITHUB_TOKEN }}" + SHA: ${{ github.event.pull_request.head.sha || github.sha }} + REF: ${{ github.ref }} + REPO_URL: ${{ github.server_url }}/${{ github.repository }} + run: | + rm -rf ac + mkdir -p ac/ansible_collections/mortis + git clone "$REPO_URL" ac/ansible_collections/mortis/kamino + cd ac/ansible_collections/mortis/kamino + # A clone has no refs/pull/*: fetch the run's ref when the sha is not on a branch. + git checkout "$SHA" || { git fetch origin "$REF" && git checkout "$SHA"; } + echo "Checked out $(git rev-parse HEAD)" + + # molecule test destroys its instance on success and on failure. + - name: Run the scenarios + working-directory: ac/ansible_collections/mortis/kamino + run: | + # molecule calls ansible-config and ansible-playbook by name + export PATH="$MOLECULE_VENV/bin:$PATH" + # the collection under test first, then what the roles use + export ANSIBLE_COLLECTIONS_PATH="$(cd ../../.. && pwd):$MOLECULE_COLLECTIONS" + failed="" + ran=0 + for cfg in extensions/molecule/*/molecule.yml; do + [ -e "$cfg" ] || continue + name="$(basename "$(dirname "$cfg")")" + echo "::group::molecule test: $name" + molecule test -s "$name" || failed="$failed $name" + ran=$((ran + 1)) + echo "::endgroup::" + done + for cfg in roles/*/molecule/*/molecule.yml; do + [ -e "$cfg" ] || continue + role="${cfg#roles/}" + role="${role%%/*}" + name="$(basename "$(dirname "$cfg")")" + echo "::group::molecule test: $role/$name" + (cd "roles/$role" && molecule test -s "$name") || failed="$failed $role/$name" + ran=$((ran + 1)) + echo "::endgroup::" + done + echo "Scenarios run: $ran" + test "$ran" -gt 0 || { echo "::error::no molecule scenario found"; exit 1; } + test -z "$failed" || { echo "::error::Failed:$failed"; exit 1; } diff --git a/extensions/molecule/image-smoke/converge.yml b/extensions/molecule/image-smoke/converge.yml new file mode 100644 index 0000000..e017fe3 --- /dev/null +++ b/extensions/molecule/image-smoke/converge.yml @@ -0,0 +1,7 @@ +--- +- name: Converge + hosts: all + gather_facts: true + tasks: + - name: Reach the instance over the container connection + ansible.builtin.ping: diff --git a/extensions/molecule/image-smoke/molecule.yml b/extensions/molecule/image-smoke/molecule.yml new file mode 100644 index 0000000..94e7c07 --- /dev/null +++ b/extensions/molecule/image-smoke/molecule.yml @@ -0,0 +1,27 @@ +--- +# Tests the molecule test image itself (images/molecule-ubuntu2404): the contract the +# role scenarios rely on. Same instance settings as a role scenario: systemd needs a +# writable cgroup, the firewall tools need NET_ADMIN, nothing is privileged. The image +# comes from the environment (MOLECULE_IMAGE, set by .gitea/workflows/molecule.yml). +driver: + name: docker +platforms: + - name: image-smoke + image: ${MOLECULE_IMAGE} + pre_build_image: true + pull: true + command: /sbin/init + cgroupns_mode: host + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:rw + tmpfs: + - /run + - /run/lock + capabilities: + - NET_ADMIN + security_opts: + - apparmor=unconfined +provisioner: + name: ansible +verifier: + name: ansible diff --git a/extensions/molecule/image-smoke/verify.yml b/extensions/molecule/image-smoke/verify.yml new file mode 100644 index 0000000..d0b7295 --- /dev/null +++ b/extensions/molecule/image-smoke/verify.yml @@ -0,0 +1,58 @@ +--- +- name: Verify the molecule image contract + hosts: all + gather_facts: true + tasks: + - name: The instance is Ubuntu 24.04 with systemd as the service manager + ansible.builtin.assert: + that: + - ansible_facts['distribution'] == 'Ubuntu' + - ansible_facts['distribution_version'] == '24.04' + - ansible_facts['service_mgr'] == 'systemd' + quiet: true + + - name: Gather package facts + ansible.builtin.package_facts: + manager: auto + + - name: The packages the roles manage are preinstalled + ansible.builtin.assert: + that: item in ansible_facts['packages'] + quiet: true + loop: + - systemd + - systemd-sysv + - dbus + - sudo + - iproute2 + - ca-certificates + - python3 + - python3-apt + - python3-systemd + - iptables + - ufw + - fail2ban + - openssh-server + + - name: Query the units a role scenario relies on + ansible.builtin.systemd: + name: "{{ item }}" + register: kamino_smoke_units + loop: + - dbus + - ssh + + - name: dbus is running and ssh is enabled + ansible.builtin.assert: + that: + - (kamino_smoke_units.results | selectattr('item', 'equalto', 'dbus') | first).status.ActiveState == 'active' + - (kamino_smoke_units.results | selectattr('item', 'equalto', 'ssh') | first).status.UnitFileState == 'enabled' + quiet: true + + - name: The Python bindings Ansible's apt and systemd support need import + ansible.builtin.command: /usr/bin/python3 -c 'import apt, systemd.journal' + changed_when: false + + - name: NET_ADMIN is granted, so the firewall tools can work + ansible.builtin.command: iptables -S + changed_when: false -- 2.43.0 From 29278e96252d43240e798d5b4867bc0e33cabfbc Mon Sep 17 00:00:00 2001 From: Claude Code AI - Gitea MCP <3+claude@noreply.git.rkdr.net> Date: Sun, 25 Oct 2026 12:11:51 +0000 Subject: [PATCH 2/4] fix(molecule): capitalise a task name and repeat the paths instead of using an anchor ansible-lint name[casing] on the smoke verify task; and the workflow trigger paths are written out for both events (YAML anchors in an `on:` block are not something to rely on in Gitea's workflow parser). Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01MmzvM9skAvYcph2c9EiPcm --- .gitea/workflows/molecule.yml | 10 ++++++++-- extensions/molecule/image-smoke/verify.yml | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/.gitea/workflows/molecule.yml b/.gitea/workflows/molecule.yml index e2a8c3f..c8fe3a9 100644 --- a/.gitea/workflows/molecule.yml +++ b/.gitea/workflows/molecule.yml @@ -21,7 +21,7 @@ on: # yamllint disable-line rule:truthy pull_request: branches: - main - paths: &paths + paths: - 'roles/**' - 'extensions/**' - 'plugins/**' @@ -31,7 +31,13 @@ on: # yamllint disable-line rule:truthy push: branches: - main - paths: *paths + paths: + - 'roles/**' + - 'extensions/**' + - 'plugins/**' + - 'meta/**' + - 'galaxy.yml' + - '.gitea/workflows/molecule.yml' workflow_dispatch: {} permissions: diff --git a/extensions/molecule/image-smoke/verify.yml b/extensions/molecule/image-smoke/verify.yml index d0b7295..a681482 100644 --- a/extensions/molecule/image-smoke/verify.yml +++ b/extensions/molecule/image-smoke/verify.yml @@ -42,7 +42,7 @@ - dbus - ssh - - name: dbus is running and ssh is enabled + - name: The dbus unit is running and ssh is enabled ansible.builtin.assert: that: - (kamino_smoke_units.results | selectattr('item', 'equalto', 'dbus') | first).status.ActiveState == 'active' -- 2.43.0 From 0211a639238cd2439a44944067922d09bd108053 Mon Sep 17 00:00:00 2001 From: Claude Code AI - Gitea MCP <3+claude@noreply.git.rkdr.net> Date: Sun, 25 Oct 2026 12:14:52 +0000 Subject: [PATCH 3/4] fix(molecule): satisfy yamllint and shellcheck, and keep molecule's collection install job-local yamllint line-length on the MOLECULE_IMAGE value (166 > 160) and shellcheck SC2155 on the export. And: the first run showed molecule installing the collection under test into the runner user's ~/.ansible/collections and warning about the duplicate in the job tree. That copy outlives the job and the version stays 0.1.0, so a later run could resolve a stale one. ANSIBLE_HOME now points into the job tree, and a copy left by earlier runs is removed. Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01MmzvM9skAvYcph2c9EiPcm --- .gitea/workflows/molecule.yml | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/.gitea/workflows/molecule.yml b/.gitea/workflows/molecule.yml index c8fe3a9..6aa4327 100644 --- a/.gitea/workflows/molecule.yml +++ b/.gitea/workflows/molecule.yml @@ -63,7 +63,8 @@ jobs: MOLECULE_COLLECTIONS: /opt/molecule-collections # Used by the scenarios as `image: ${MOLECULE_IMAGE}`; set it the same way to run # one locally. - MOLECULE_IMAGE: git.rkdr.net/mortis/molecule-ubuntu2404:0.1.0@sha256:80dbfa7f88309072e954ae20e80ee8171bd750abc7c1d9563c746bf6f0121f04 + MOLECULE_IMAGE: >- + git.rkdr.net/mortis/molecule-ubuntu2404:0.1.0@sha256:80dbfa7f88309072e954ae20e80ee8171bd750abc7c1d9563c746bf6f0121f04 steps: # Provisioned by the gitea_runner role (install_services); fail with a clear # message when this runs before it has. @@ -96,8 +97,15 @@ jobs: run: | # molecule calls ansible-config and ansible-playbook by name export PATH="$MOLECULE_VENV/bin:$PATH" - # the collection under test first, then what the roles use - export ANSIBLE_COLLECTIONS_PATH="$(cd ../../.. && pwd):$MOLECULE_COLLECTIONS" + # The collection under test first, then what the roles use. molecule also + # installs the collection under test into ANSIBLE_HOME; keep that inside the + # job tree so no run resolves a copy another run left in the runner user's + # home (the version stays 0.1.0, so a stale copy would look current). The rm + # clears a copy left there by runs before this was set. + ac_root="$(cd ../../.. && pwd)" + export ANSIBLE_HOME="$ac_root/.ansible" + export ANSIBLE_COLLECTIONS_PATH="$ac_root:$MOLECULE_COLLECTIONS" + rm -rf "$HOME/.ansible/collections/ansible_collections/mortis" failed="" ran=0 for cfg in extensions/molecule/*/molecule.yml; do -- 2.43.0 From 0b87c8f14b727bf82206b93ede4f3d6ea7bf9936 Mon Sep 17 00:00:00 2001 From: Claude Code AI - Gitea MCP <3+claude@noreply.git.rkdr.net> Date: Sun, 25 Oct 2026 12:31:55 +0000 Subject: [PATCH 4/4] fix(molecule): wrap the tooling check line that exceeds the yamllint line length The long line was the `test -x` check (166 > 160), not the image reference. Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01MmzvM9skAvYcph2c9EiPcm --- .gitea/workflows/molecule.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.gitea/workflows/molecule.yml b/.gitea/workflows/molecule.yml index 6aa4327..888cf1c 100644 --- a/.gitea/workflows/molecule.yml +++ b/.gitea/workflows/molecule.yml @@ -70,7 +70,10 @@ jobs: # message when this runs before it has. - name: Check the provisioned tooling run: | - test -x "$MOLECULE_VENV/bin/molecule" || { echo "::error::molecule is not installed on this runner: run install_services for kamino-runner first"; exit 1; } + if ! test -x "$MOLECULE_VENV/bin/molecule"; then + echo "::error::molecule is not installed on this runner: run install_services for kamino-runner first" + exit 1 + fi docker version --format '{{.Server.Version}}' || { echo "::error::the Docker daemon is not reachable by the runner user"; exit 1; } # The Collection must sit at ansible_collections/mortis/kamino for FQCNs to resolve. -- 2.43.0