From db52adcb813eb93cffd2b728e88478c72ea15406 Mon Sep 17 00:00:00 2001 From: Defame1297 Date: Sat, 14 Nov 2026 11:06:17 +0000 Subject: [PATCH 1/3] ci(molecule): cancel superseded pull request runs A new commit on a pull request now cancels its running Molecule run, as for Lint and Build; a run on main is never cancelled (its group is the commit SHA). The old global concurrency group kept two runs off the runner's shared Docker daemon, whose container names are fixed. That is now the runner's single slot (gitea_runner_capacity: 1), as the workflow comment and CLAUDE.md say. A cancelled run is killed before molecule can destroy its container, so the run step first removes the containers of every scenario by their exact platform names, whether or not this run selects that scenario. Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_014uGZTNmHMc85bomfevwUDG --- .gitea/workflows/molecule.yml | 22 ++++++++++++++++++---- CLAUDE.md | 4 +++- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/.gitea/workflows/molecule.yml b/.gitea/workflows/molecule.yml index 8bc3239..6ff87c2 100644 --- a/.gitea/workflows/molecule.yml +++ b/.gitea/workflows/molecule.yml @@ -41,10 +41,15 @@ on: # yamllint disable-line rule:truthy permissions: contents: read -# Scenarios use fixed container names on the runner's shared Docker daemon. +# A pull request run is cancelled when a newer commit is pushed to the same pull request (the +# same rule as lint.yml and build.yml); a run on main is never cancelled, so its group is the +# commit SHA. Scenarios use fixed container names on the runner's shared Docker daemon, so two +# runs must not overlap. The group no longer guarantees that (it is per pull request now): the +# runner's single slot does (gitea_runner_capacity: 1 in the maintainer's environment +# repository). Raise that capacity and this needs a lock or a shared group again. concurrency: - group: molecule - cancel-in-progress: false + group: molecule-${{ github.event_name == 'pull_request' && github.ref || github.sha }} + cancel-in-progress: ${{ github.event_name == 'pull_request' }} jobs: molecule: @@ -100,7 +105,9 @@ jobs: # A pull request runs only the scenarios of the roles it changes (scripts/select_molecule_scenarios.py # explains the rules); a push to main and a manual dispatch run all of them. - # molecule test destroys its instance on success and on failure. + # molecule test destroys its instance on success and on failure; a cancelled run is killed + # before it can, so the step first removes what such a run left, since the next run may not + # select the same scenarios. - name: Run the scenarios working-directory: ac/ansible_collections/mortis/kamino env: @@ -108,6 +115,13 @@ jobs: # The workflow only runs for pull requests to main; lint.yml uses the same constant. BASE_REF: origin/main run: | + # The platform names of every scenario, anchored: -instance and image-smoke[-2604]. + # Assigned first so that a failing `docker ps` fails the step instead of looking empty. + stale="$(docker ps -aq --filter 'name=^/[a-z0-9-]+-instance$' --filter 'name=^/image-smoke(-2604)?$')" + if [ -n "$stale" ]; then + # shellcheck disable=SC2086 # container ids, one word each + docker rm -f $stale + fi # 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. molecule also diff --git a/CLAUDE.md b/CLAUDE.md index 26d9b2d..275869f 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -64,7 +64,9 @@ Single-context: `GLOSSARY.md` and `docs/adr/` at the root, both created lazily. (a pull request cannot edit its own rules): only the scenarios of the roles it changes, none for a diff of only its IGNORED paths, a failure for a changed role with no scenario, and every scenario for any other file, for every push to `main` and for manual dispatch. A new file outside `roles//` runs everything until it - is added to IGNORED, which is right only when no scenario reads it. + is added to IGNORED, which is right only when no scenario reads it. A new commit cancels the pull request's + running Molecule run, and the step first removes containers a cancelled run left; two runs never overlap + because the runner has a single slot, so raising its capacity needs a lock or a shared concurrency group. - Molecule discovers `extensions/molecule/*/` and `roles/*/molecule/*/`. The `image-smoke` and `image-smoke-2604` scenarios test the molecule images themselves (24.04 and 26.04); a role scenario that must pass on both takes `image: ${MOLECULE_IMAGE}` or `${MOLECULE_IMAGE_2604}` per platform. From 792b3414d3ca3c533222245ceadb1964f033d1b2 Mon Sep 17 00:00:00 2001 From: Defame1297 Date: Sat, 14 Nov 2026 11:06:18 +0000 Subject: [PATCH 2/3] ci(molecule): drop the leading destroy from every scenario's test sequence The first destroy runs against a container that is not there and only waits out the Docker driver's fixed 5 s poll, about 6 s per scenario and 42 s per full run. The run step already removes what a killed run left, and molecule's state file lives under the job's own ANSIBLE_HOME (Runtime(isolated=False)), which is deleted with the checkout, so a cancelled run cannot make the next one skip create or prepare. The rest of the sequence is molecule's default. Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_014uGZTNmHMc85bomfevwUDG --- CLAUDE.md | 3 +++ .../molecule/image-smoke-2604/molecule.yml | 17 +++++++++++++++++ extensions/molecule/image-smoke/molecule.yml | 17 +++++++++++++++++ roles/docker/molecule/default/molecule.yml | 17 +++++++++++++++++ roles/fail2ban/molecule/default/molecule.yml | 17 +++++++++++++++++ .../molecule/default/molecule.yml | 17 +++++++++++++++++ .../molecule/default/molecule.yml | 17 +++++++++++++++++ .../molecule/default/molecule.yml | 17 +++++++++++++++++ 8 files changed, 122 insertions(+) diff --git a/CLAUDE.md b/CLAUDE.md index 275869f..362fca5 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -67,6 +67,9 @@ Single-context: `GLOSSARY.md` and `docs/adr/` at the root, both created lazily. is added to IGNORED, which is right only when no scenario reads it. A new commit cancels the pull request's running Molecule run, and the step first removes containers a cancelled run left; two runs never overlap because the runner has a single slot, so raising its capacity needs a lock or a shared concurrency group. +- Every scenario sets `scenario.test_sequence` to molecule's default minus the leading `destroy` (the workflow + clears stale containers first, and the molecule state lives in the job's own `ANSIBLE_HOME`, so a killed run leaves + none behind); copy it into a new scenario. - Molecule discovers `extensions/molecule/*/` and `roles/*/molecule/*/`. The `image-smoke` and `image-smoke-2604` scenarios test the molecule images themselves (24.04 and 26.04); a role scenario that must pass on both takes `image: ${MOLECULE_IMAGE}` or `${MOLECULE_IMAGE_2604}` per platform. diff --git a/extensions/molecule/image-smoke-2604/molecule.yml b/extensions/molecule/image-smoke-2604/molecule.yml index e2d5479..00db4cd 100644 --- a/extensions/molecule/image-smoke-2604/molecule.yml +++ b/extensions/molecule/image-smoke-2604/molecule.yml @@ -25,3 +25,20 @@ provisioner: name: ansible verifier: name: ansible +scenario: + # molecule's default sequence minus its first destroy: the workflow removes what a killed run + # left before any scenario starts, so that destroy only waits out the + # driver's 5 s poll on a container that is not there. After an aborted local run, run + # `molecule destroy` yourself. + test_sequence: + - dependency + - cleanup + - syntax + - create + - prepare + - converge + - idempotence + - side_effect + - verify + - cleanup + - destroy diff --git a/extensions/molecule/image-smoke/molecule.yml b/extensions/molecule/image-smoke/molecule.yml index 94e7c07..ff89ab1 100644 --- a/extensions/molecule/image-smoke/molecule.yml +++ b/extensions/molecule/image-smoke/molecule.yml @@ -25,3 +25,20 @@ provisioner: name: ansible verifier: name: ansible +scenario: + # molecule's default sequence minus its first destroy: the workflow removes what a killed run + # left before any scenario starts, so that destroy only waits out the + # driver's 5 s poll on a container that is not there. After an aborted local run, run + # `molecule destroy` yourself. + test_sequence: + - dependency + - cleanup + - syntax + - create + - prepare + - converge + - idempotence + - side_effect + - verify + - cleanup + - destroy diff --git a/roles/docker/molecule/default/molecule.yml b/roles/docker/molecule/default/molecule.yml index bc10d73..ecc4f9b 100644 --- a/roles/docker/molecule/default/molecule.yml +++ b/roles/docker/molecule/default/molecule.yml @@ -26,3 +26,20 @@ provisioner: name: ansible verifier: name: ansible +scenario: + # molecule's default sequence minus its first destroy: the workflow removes what a killed run + # left before any scenario starts, so that destroy only waits out the + # driver's 5 s poll on a container that is not there. After an aborted local run, run + # `molecule destroy` yourself. + test_sequence: + - dependency + - cleanup + - syntax + - create + - prepare + - converge + - idempotence + - side_effect + - verify + - cleanup + - destroy diff --git a/roles/fail2ban/molecule/default/molecule.yml b/roles/fail2ban/molecule/default/molecule.yml index 453236e..44d84b3 100644 --- a/roles/fail2ban/molecule/default/molecule.yml +++ b/roles/fail2ban/molecule/default/molecule.yml @@ -24,3 +24,20 @@ provisioner: name: ansible verifier: name: ansible +scenario: + # molecule's default sequence minus its first destroy: the workflow removes what a killed run + # left before any scenario starts, so that destroy only waits out the + # driver's 5 s poll on a container that is not there. After an aborted local run, run + # `molecule destroy` yourself. + test_sequence: + - dependency + - cleanup + - syntax + - create + - prepare + - converge + - idempotence + - side_effect + - verify + - cleanup + - destroy diff --git a/roles/network_interfaces/molecule/default/molecule.yml b/roles/network_interfaces/molecule/default/molecule.yml index e8380d5..4e79c56 100644 --- a/roles/network_interfaces/molecule/default/molecule.yml +++ b/roles/network_interfaces/molecule/default/molecule.yml @@ -24,3 +24,20 @@ provisioner: name: ansible verifier: name: ansible +scenario: + # molecule's default sequence minus its first destroy: the workflow removes what a killed run + # left before any scenario starts, so that destroy only waits out the + # driver's 5 s poll on a container that is not there. After an aborted local run, run + # `molecule destroy` yourself. + test_sequence: + - dependency + - cleanup + - syntax + - create + - prepare + - converge + - idempotence + - side_effect + - verify + - cleanup + - destroy diff --git a/roles/system_baseline/molecule/default/molecule.yml b/roles/system_baseline/molecule/default/molecule.yml index f67f633..38d5d54 100644 --- a/roles/system_baseline/molecule/default/molecule.yml +++ b/roles/system_baseline/molecule/default/molecule.yml @@ -31,3 +31,20 @@ provisioner: skip-tags: molecule-notest,notest,sysctl,secure_tmp,update,timezone verifier: name: ansible +scenario: + # molecule's default sequence minus its first destroy: the workflow removes what a killed run + # left before any scenario starts, so that destroy only waits out the + # driver's 5 s poll on a container that is not there. After an aborted local run, run + # `molecule destroy` yourself. + test_sequence: + - dependency + - cleanup + - syntax + - create + - prepare + - converge + - idempotence + - side_effect + - verify + - cleanup + - destroy diff --git a/roles/systemd_hardening/molecule/default/molecule.yml b/roles/systemd_hardening/molecule/default/molecule.yml index 7b5f79b..2794fc6 100644 --- a/roles/systemd_hardening/molecule/default/molecule.yml +++ b/roles/systemd_hardening/molecule/default/molecule.yml @@ -24,3 +24,20 @@ provisioner: name: ansible verifier: name: ansible +scenario: + # molecule's default sequence minus its first destroy: the workflow removes what a killed run + # left before any scenario starts, so that destroy only waits out the + # driver's 5 s poll on a container that is not there. After an aborted local run, run + # `molecule destroy` yourself. + test_sequence: + - dependency + - cleanup + - syntax + - create + - prepare + - converge + - idempotence + - side_effect + - verify + - cleanup + - destroy From 25bca2ebffe261cfaf826aac05ba88c83e3275c8 Mon Sep 17 00:00:00 2001 From: Defame1297 Date: Sat, 14 Nov 2026 11:06:59 +0000 Subject: [PATCH 3/3] ci(molecule): run every scenario nightly A pull request runs only the scenarios of the roles it changes, so drift in the others (a package mirror, the runner's molecule venv) would wait for the next push to main. A nightly run of everything bounds that. It is scheduled after Renovate's run, since the runner has a single slot. Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_014uGZTNmHMc85bomfevwUDG --- .gitea/workflows/molecule.yml | 5 +++++ CLAUDE.md | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/.gitea/workflows/molecule.yml b/.gitea/workflows/molecule.yml index 6ff87c2..7a69038 100644 --- a/.gitea/workflows/molecule.yml +++ b/.gitea/workflows/molecule.yml @@ -36,6 +36,11 @@ on: # yamllint disable-line rule:truthy - 'meta/**' - 'galaxy.yml' - '.gitea/workflows/molecule.yml' + # Every scenario, nightly: a pull request runs only the scenarios of the roles it changes, so + # drift in the others (a package mirror, the runner's molecule venv) would otherwise wait for + # the next push to main. After Renovate's 03:17 run, which can take 30 minutes of the one slot. + schedule: + - cron: "43 4 * * *" workflow_dispatch: {} permissions: diff --git a/CLAUDE.md b/CLAUDE.md index 362fca5..cfe8e1a 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -63,7 +63,7 @@ Single-context: `GLOSSARY.md` and `docs/adr/` at the root, both created lazily. What a pull request runs is chosen by `scripts/select_molecule_scenarios.py`, run from the base branch's copy (a pull request cannot edit its own rules): only the scenarios of the roles it changes, none for a diff of only its IGNORED paths, a failure for a changed role with no scenario, and every scenario for any other file, - for every push to `main` and for manual dispatch. A new file outside `roles//` runs everything until it + for every push to `main`, for manual dispatch and for the nightly run (04:43 UTC, after Renovate's). A new file outside `roles//` runs everything until it is added to IGNORED, which is right only when no scenario reads it. A new commit cancels the pull request's running Molecule run, and the step first removes containers a cancelled run left; two runs never overlap because the runner has a single slot, so raising its capacity needs a lock or a shared concurrency group.