ci(lint): resolve the Collection's own roles and drop mock_roles
Step 5 of #118. The scenarios' converge plays call the roles by FQCN (mortis.kamino.<role>), which only resolves from an ansible_collections/<namespace>/<name> directory, and a checkout is not one, so .ansible-lint listed the five roles in mock_roles and ansible-lint never checked those plays against the real roles. scripts/ansible-lint.sh, which the ansible-lint hook runs in CI and locally, now links the checkout as ansible_collections/<namespace>/<name> in a temporary root (namespace and name read from galaxy.yml), puts that root first on ANSIBLE_COLLECTIONS_PATH and removes it on exit, so ansible-lint reads the checkout itself. Removing mock_roles reproduced five syntax-check[specific] role-not-found errors; with the link the run passes with no warnings, locally and with CI's preset path. A bare ansible-lint, outside the hook, does not get the link; .ansible-lint says so. No image input changes: .pre-commit-config.yaml, requirements and images/** are untouched, so no version bump or second pull request. Closes the last open item of #118. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_014uGZTNmHMc85bomfevwUDG
This commit is contained in:
1 parent
8c743c125a
commit
3289c0d430
3 files changed
+103
-20
No files matched your search
+22
-1
@@ -7,6 +7,12 @@
|
||||
# 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.
|
||||
#
|
||||
# The Collection's own role names (mortis.kamino.<role>, which the molecule scenarios' converge
|
||||
# plays use) only resolve from an <namespace>/<name> directory under an ansible_collections root,
|
||||
# and a checkout is not one. So the checkout is linked into a temporary root, put first on the
|
||||
# collections path, and ansible-lint reads the checkout itself through it (#118 step 5). The link
|
||||
# is removed on exit.
|
||||
set -euo pipefail
|
||||
|
||||
root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||||
@@ -21,4 +27,19 @@ if [ -z "${ANSIBLE_COLLECTIONS_PATH:-}" ]; then
|
||||
export ANSIBLE_COLLECTIONS_PATH="$root/.ansible/collections"
|
||||
fi
|
||||
|
||||
exec ansible-lint --offline --nocolor
|
||||
# The Collection's own name, from galaxy.yml, so a rename needs no edit here.
|
||||
namespace="$(sed -n 's/^namespace: *//p' galaxy.yml)"
|
||||
name="$(sed -n 's/^name: *//p' galaxy.yml)"
|
||||
if [ -z "$namespace" ] || [ -z "$name" ]; then
|
||||
echo "error: no namespace and name in $root/galaxy.yml" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
link_root="$(mktemp -d)"
|
||||
trap 'rm -rf "$link_root"' EXIT
|
||||
mkdir -p "$link_root/ansible_collections/$namespace"
|
||||
ln -s "$root" "$link_root/ansible_collections/$namespace/$name"
|
||||
export ANSIBLE_COLLECTIONS_PATH="$link_root:$ANSIBLE_COLLECTIONS_PATH"
|
||||
|
||||
# Not exec: the trap above has to run when ansible-lint ends.
|
||||
ansible-lint --offline --nocolor
|
||||
Reference in new issue
Block a user