Files
Kamino/scripts/ansible-lint.sh
T
Defame1297andClaude Sonnet 5.5 bdb34cf98e
Build / build (pull_request) Successful in 12s
Lint / lint (pull_request) Successful in 43s
Molecule / molecule (pull_request) Failing after 49s
fix(dev): run ansible-lint against the clone's pinned collections from any shell
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
2026-11-14 14:14:37 +00:00

25 lines
1.1 KiB
Bash
Executable File

#!/usr/bin/env bash
# The ansible-lint pre-commit hook: ansible-lint --offline against the pinned collections.
#
# CI sets ANSIBLE_COLLECTIONS_PATH (the ci image bakes requirements.yml into /opt/collections) and
# this script then leaves the environment alone. A local run does not set it, and ansible-lint would
# resolve modules from the control host's ~/.ansible, whose collection versions need not be the
# ones CI tests against (#118, #80). So when the variable is unset, this script uses the collections
# scripts/dev-setup.sh installed into .ansible/collections of this clone, and fails with the fix
# when they are missing. That covers `git commit` and a bare `pre-commit run` alike.
set -euo pipefail
root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
cd "$root"
if [ -z "${ANSIBLE_COLLECTIONS_PATH:-}" ]; then
if [ ! -d "$root/.ansible/collections/ansible_collections" ]; then
echo "error: the pinned collections are not installed in $root/.ansible/collections; run scripts/dev-setup.sh" >&2
exit 1
fi
export ANSIBLE_HOME="$root/.ansible"
export ANSIBLE_COLLECTIONS_PATH="$root/.ansible/collections"
fi
exec ansible-lint --offline --nocolor