ci: bake the dependency collections into the ci image and drop mock_modules / mock_roles #118

Closed
opened 2026-11-14 12:40:29 +00:00 by Claude · 1 comment
Owner

Problem

system_baseline (#114, 1.3.0) is the first role that calls modules from other collections: community.general.locale_gen and .timezone, and ansible.posix.sysctl and .mount. galaxy.yml now declares community.general >=14.0.0 and ansible.posix >=2.2.0.

  • Lint: the Lint job runs ansible-lint --offline in the ci image, which has no collections, so these modules could not be resolved (syntax-check[unknown-module]). They are listed in mock_modules in .ansible-lint as a stopgap, so lint does not check those tasks' module arguments.
  • Local runs: local ansible-lint resolved them from a user-wide collections path, which had community.general 13.5.0, not the 14.0.0 that CI tests against. The local result differed from CI (the shared-state problem of #80).
  • Molecule: it reads a collections directory provisioned on the runner. The environment repo's gitea_runner role installs that directory from the environment repo's own requirements.yml, so Kamino's tests depend on pins Kamino does not own.

mock_roles is a separate stopgap. CI checks the Collection out outside an ansible_collections/mortis/kamino path, so the scenarios' FQCN role names do not resolve.

Proposal

  1. Add a Kamino-owned requirements.yml with exact pins (currently community.general 14.0.0, ansible.posix 2.2.2), tracked by Renovate.
  2. Install it into the ci image with ansible-galaxy collection install -r requirements.yml -p /opt/collections and set ANSIBLE_COLLECTIONS_PATH. Add the file to /opt/ci-pins.sha256, so a PR that changes a pin falls back to installing at run time, the same way as requirements-dev.txt. Lint stays --offline. Drop mock_modules.
  3. Let Molecule install from the same file instead of the runner-provisioned /opt/molecule-collections.
  4. Have scripts/dev-setup.sh install the pins into a project-local ANSIBLE_HOME, so local lint matches CI (part of #80).
  5. Separately: check the repo out or link it under ansible_collections/mortis/kamino in the Lint job and drop mock_roles.

Tradeoff

Every collection bump becomes an image version bump plus a pin PR, one more step in an already long release chain.

Acceptance

  • .ansible-lint has no mock_modules (and, after step 5, no mock_roles).
  • Lint, Molecule and the local hooks resolve the same collection versions, from this repo's pins.

🤖 Generated with Claude Code

## Problem `system_baseline` (#114, 1.3.0) is the first role that calls modules from other collections: `community.general.locale_gen` and `.timezone`, and `ansible.posix.sysctl` and `.mount`. `galaxy.yml` now declares `community.general >=14.0.0` and `ansible.posix >=2.2.0`. - **Lint:** the Lint job runs `ansible-lint --offline` in the `ci` image, which has no collections, so these modules could not be resolved (`syntax-check[unknown-module]`). They are listed in `mock_modules` in `.ansible-lint` as a stopgap, so lint does not check those tasks' module arguments. - **Local runs:** local `ansible-lint` resolved them from a user-wide collections path, which had `community.general` 13.5.0, not the 14.0.0 that CI tests against. The local result differed from CI (the shared-state problem of #80). - **Molecule:** it reads a collections directory provisioned on the runner. The environment repo's `gitea_runner` role installs that directory from the environment repo's own `requirements.yml`, so Kamino's tests depend on pins Kamino does not own. `mock_roles` is a separate stopgap. CI checks the Collection out outside an `ansible_collections/mortis/kamino` path, so the scenarios' FQCN role names do not resolve. ## Proposal 1. Add a Kamino-owned `requirements.yml` with exact pins (currently `community.general` 14.0.0, `ansible.posix` 2.2.2), tracked by Renovate. 2. Install it into the `ci` image with `ansible-galaxy collection install -r requirements.yml -p /opt/collections` and set `ANSIBLE_COLLECTIONS_PATH`. Add the file to `/opt/ci-pins.sha256`, so a PR that changes a pin falls back to installing at run time, the same way as `requirements-dev.txt`. Lint stays `--offline`. Drop `mock_modules`. 3. Let Molecule install from the same file instead of the runner-provisioned `/opt/molecule-collections`. 4. Have `scripts/dev-setup.sh` install the pins into a project-local `ANSIBLE_HOME`, so local lint matches CI (part of #80). 5. Separately: check the repo out or link it under `ansible_collections/mortis/kamino` in the Lint job and drop `mock_roles`. ## Tradeoff Every collection bump becomes an image version bump plus a pin PR, one more step in an already long release chain. ## Acceptance - `.ansible-lint` has no `mock_modules` (and, after step 5, no `mock_roles`). - Lint, Molecule and the local hooks resolve the same collection versions, from this repo's pins. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Author
Owner

Done; closing. All five steps landed, and the acceptance holds on main (checked in the CI runs after the merges, not only locally).

What landed

  1. Kamino-owned pins: requirements.yml (community.general 14.0.0, ansible.posix 2.2.2), tracked by Renovate's ansible-galaxy manager. The bot-diff gate lets a bot change only its version: lines. (#121)
  2. Baked into the ci image: /opt/collections, found through ANSIBLE_COLLECTIONS_PATH, and the file is in /opt/ci-pins.sha256, so a PR that changes a pin installs them for its own run. mock_modules is gone from .ansible-lint. (#121, image fixes in #123)
  3. Molecule installs from the same file instead of the runner's /opt/molecule-collections, cached on the runner by checksum. The Docker driver's own collection (community.docker) is pinned separately in extensions/molecule/requirements.yml, because it is a test-harness dependency and the roles do not call it. (#121, fix in the same PR)
  4. scripts/dev-setup.sh installs the pins into .ansible/collections of the clone, and the ansible-lint hook (scripts/ansible-lint.sh) uses them when ANSIBLE_COLLECTIONS_PATH is unset, also from a bare pre-commit run. (#121, #126)
  5. mock_roles is gone: the same wrapper links the checkout as ansible_collections/<namespace>/<name> in a temporary directory, so the scenarios' FQCN role names resolve and the converge plays are linted against the real roles. (#126)

Pin-follow PRs: #125 (ci 0.2.17) and #127 (ci 0.2.18). lint.yml and build.yml now pin ci:0.2.18@sha256:ff30bb7f…66a8.

Acceptance

  • .ansible-lint has no mock_modules and no mock_roles.
  • Lint, Molecule and the local hooks resolve the same collection versions, from this repository's pins. On main the Lint job prints The pin files match the ci image; using the baked tools. and passes ansible-lint with no mock list; Molecule passes with the pinned collections.

Tradeoff, as the issue said

Every collection bump is now an image version bump plus a pin PR. The ci image build prints the compressed size of each layer directory (/opt/pre-commit 58 MB, /opt/python 62 MB, /opt/venv 44 MB, /opt/collections 3 MB), which is the number the 100 MB limit applies to.

Things that came up on the way

  • The Molecule scenarios failed after #121 because dropping the runner's collections directory also dropped community.docker; fixed in the same PR.
  • The first 0.2.16 image push got a 413 from Cloudflare (the /opt/pre-commit layer passed 100 MB with the new ruff and shellcheck environments). The unused Go binaries that pre-commit installs next to gitleaks and actionlint are now deleted. (#123)
  • ansible-test sanity reports findings that ruff and the other hooks do not, and failed #126's Build check on a name only its pylint disallows. A pre-push hook now runs it on HEAD. (#126)

Not changed: renovate.json's other rules, the molecule image pins, and the other open issues.

Done; closing. All five steps landed, and the acceptance holds on `main` (checked in the CI runs after the merges, not only locally). ## What landed 1. **Kamino-owned pins:** `requirements.yml` (community.general 14.0.0, ansible.posix 2.2.2), tracked by Renovate's `ansible-galaxy` manager. The bot-diff gate lets a bot change only its `version:` lines. (#121) 2. **Baked into the `ci` image:** `/opt/collections`, found through `ANSIBLE_COLLECTIONS_PATH`, and the file is in `/opt/ci-pins.sha256`, so a PR that changes a pin installs them for its own run. `mock_modules` is gone from `.ansible-lint`. (#121, image fixes in #123) 3. **Molecule installs from the same file** instead of the runner's `/opt/molecule-collections`, cached on the runner by checksum. The Docker driver's own collection (`community.docker`) is pinned separately in `extensions/molecule/requirements.yml`, because it is a test-harness dependency and the roles do not call it. (#121, fix in the same PR) 4. **`scripts/dev-setup.sh`** installs the pins into `.ansible/collections` of the clone, and the `ansible-lint` hook (`scripts/ansible-lint.sh`) uses them when `ANSIBLE_COLLECTIONS_PATH` is unset, also from a bare `pre-commit run`. (#121, #126) 5. **`mock_roles` is gone:** the same wrapper links the checkout as `ansible_collections/<namespace>/<name>` in a temporary directory, so the scenarios' FQCN role names resolve and the converge plays are linted against the real roles. (#126) Pin-follow PRs: #125 (`ci` 0.2.17) and #127 (`ci` 0.2.18). `lint.yml` and `build.yml` now pin `ci:0.2.18@sha256:ff30bb7f…66a8`. ## Acceptance - `.ansible-lint` has no `mock_modules` and no `mock_roles`. - Lint, Molecule and the local hooks resolve the same collection versions, from this repository's pins. On `main` the Lint job prints `The pin files match the ci image; using the baked tools.` and passes `ansible-lint` with no mock list; Molecule passes with the pinned collections. ## Tradeoff, as the issue said Every collection bump is now an image version bump plus a pin PR. The `ci` image build prints the compressed size of each layer directory (`/opt/pre-commit` 58 MB, `/opt/python` 62 MB, `/opt/venv` 44 MB, `/opt/collections` 3 MB), which is the number the 100 MB limit applies to. ## Things that came up on the way - The Molecule scenarios failed after #121 because dropping the runner's collections directory also dropped `community.docker`; fixed in the same PR. - The first 0.2.16 image push got a 413 from Cloudflare (the `/opt/pre-commit` layer passed 100 MB with the new ruff and shellcheck environments). The unused Go binaries that pre-commit installs next to `gitleaks` and `actionlint` are now deleted. (#123) - `ansible-test sanity` reports findings that ruff and the other hooks do not, and failed #126's Build check on a name only its pylint disallows. A `pre-push` hook now runs it on `HEAD`. (#126) Not changed: `renovate.json`'s other rules, the molecule image pins, and the other open issues.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Mortis/Kamino#118