fix(dev): run ansible-lint against the clone's pinned collections from any shell
Build / build (pull_request) Successful in 12s
Lint / lint (pull_request) Successful in 43s
Molecule / molecule (pull_request) Failing after 49s

The hook scripts written by dev-setup.sh exported ANSIBLE_HOME and ANSIBLE_COLLECTIONS_PATH, so only a hook run through git commit saw the pinned collections; a bare pre-commit run fell back to the control host's ~/.ansible, the drift #118 removes. The ansible-lint hook now runs scripts/ansible-lint.sh, which uses .ansible/collections of the clone when ANSIBLE_COLLECTIONS_PATH is unset, fails with the fix when they are missing, and leaves a preset path (CI's /opt/collections) alone. dev-setup.sh keeps installing the collections and no longer edits the hook scripts beyond the PATH block it always wrote.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_014uGZTNmHMc85bomfevwUDG
This commit is contained in:
Defame1297andClaude Sonnet 5.5 committed 2026-11-14 14:14:37 +00:00
1 parent 42ad8de88f
commit bdb34cf98e
7 files changed
+123 -53

No files matched your search

+8 -19
View File
@@ -1,7 +1,7 @@
#!/usr/bin/env bash
# Sets up a local checkout for development: a virtualenv with the pinned tools
# (requirements-dev.txt, the versions CI runs), the pinned collections the roles call
# (requirements.yml) and git hooks that find both.
# (requirements.yml) and git hooks that find the tools.
#
# scripts/dev-setup.sh # KAMINO_PYTHON=python3.13 scripts/dev-setup.sh to pick one
#
@@ -17,11 +17,11 @@
# Some hooks of .pre-commit-config.yaml are `language: system` (REUSE, changelog lint,
# ansible-lint): they run their tools by name, so the tools must be on PATH when git
# runs the hook. `pre-commit install` does not arrange that, so this script puts the
# virtualenv first on PATH inside the installed hook scripts. It also points ANSIBLE_HOME
# at .ansible/ of this clone and ANSIBLE_COLLECTIONS_PATH at the collections installed into
# it, so ansible-lint resolves the same collection versions as CI (the ci image bakes
# requirements.yml) and never the ones in the control host's ~/.ansible. It is idempotent;
# run it again after changing requirements-dev.txt, requirements.yml or the hook types.
# virtualenv first on PATH inside the installed hook scripts. It also installs the collections
# of requirements.yml into .ansible/collections of this clone: scripts/ansible-lint.sh (the
# ansible-lint hook) resolves modules from there, so local lint sees the collection versions CI
# does (the ci image bakes requirements.yml) and not the control host's ~/.ansible. It is
# idempotent; run it again after changing requirements-dev.txt, requirements.yml or the hook types.
set -euo pipefail
# ansible-core 2.22 (requirements-dev.txt) needs Python 3.13+. Renovate raises that pin, so
@@ -132,7 +132,6 @@ ANSIBLE_COLLECTIONS_PATH="$collections" .venv/bin/ansible-galaxy collection inst
-r requirements.yml -p "$collections"
marker="# kamino-dev-setup: virtualenv first on PATH"
collections_marker="# kamino-dev-setup: collections from this clone"
# default_install_hook_types in .pre-commit-config.yaml names these; keep in step.
for hook in pre-commit commit-msg; do
file="$(git -C "$root" rev-parse --path-format=absolute --git-path "hooks/$hook")"
@@ -140,22 +139,12 @@ for hook in pre-commit commit-msg; do
echo "error: $file was not installed by 'pre-commit install'; check default_install_hook_types in .pre-commit-config.yaml." >&2
exit 1
fi
# Each block is added on its own, so a hook installed by an older version of this script
# (PATH only) gains the collections path without a second PATH line.
add=()
if ! grep -qxF "$marker" "$file"; then
# %q shell-quotes the path: a repository path with spaces, quotes or $(...) is data.
add+=("$marker" "export PATH=$(printf '%q' "$root/.venv/bin"):\"\$PATH\"")
fi
if ! grep -qxF "$collections_marker" "$file"; then
add+=("$collections_marker" "export ANSIBLE_HOME=$(printf '%q' "$root/.ansible")")
add+=("export ANSIBLE_COLLECTIONS_PATH=$(printf '%q' "$collections")")
fi
if [ "${#add[@]}" -gt 0 ]; then
tmp="$(mktemp)"
{
head -n 1 "$file"
printf '%s\n' "${add[@]}"
# %q shell-quotes the path: a repository path with spaces, quotes or $(...) is data.
printf '%s\n' "$marker" "export PATH=$(printf '%q' "$root/.venv/bin"):\"\$PATH\""
tail -n +2 "$file"
} > "$tmp"
cat "$tmp" > "$file" # keeps the file mode of the hook