#!/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