project-config/tools/ansible-lint-roles-cache.sh
Ian Wienand 826a79f50f linter: update ansible-lint; add auto-download of roles
This updates ansible-lint to the 6.x releases.  It also updates the
ansible installed to our current zuul version.

It cleans up the config file and marks it as yaml.  A few new
exceptions are added with explainations.

We don't need to fake the zuul_return by telling ansible-lint to mock
it.  This is added to the config, and we can remove the stub file.

A constant source of problems running this locally is that you have to
have the other role repos checked out so ansible-lint can do its
checks.  Add a smaller helper script for doing this locally.  In the
gate, ANSIBLE_ROLES_PATH is set to the Zuul checkouts of these
projects.  Locally, add a smaller helper "ansible-lint-roles-cache.sh"
that pulls the projects into a .cache directory.  If they are already
there, they get updated.  By default locally we will use these
checkouts.  This way, "tox -e linters" just works without having to do
anything else.

This also modifies the xargs to run the check all at once, instead of
fork for each file.  I did try autodetection but it seems like other
yaml files in the roles/playbook directories still confuse
ansible-lint.

Also I don't think we need a ansible-playbook --syntax-check step;
ansible-lint covers that.

Change-Id: I972f73037b9f904a555b81f3835ca5261639ed01
2022-08-12 09:29:11 +10:00

39 lines
843 B
Bash
Executable File

#!/bin/bash
# This is a bit lame, but if we're running under Zuul then this is set
# to the zuul checkouts of the required roles, so no need to do
# anything here.
if [[ ! ${ANSIBLE_ROLES_PATH} =~ \.cache.* ]]; then
exit 0
fi
if [ ! -d .cache/ansible-lint ]; then
mkdir -p .cache/ansible-lint
fi
pushd .cache/ansible-lint
repos=(opendev/base-jobs
opendev/system-config
openstack/openstack-zuul-jobs
zuul/zuul-jobs)
for repo in ${repos[@]}; do
dir=$(dirname $repo)
echo "Updating Ansible roles repo ${dir}"
if [ ! -d $repo ]; then
echo "Cloning fresh"
mkdir -p $dir
pushd $dir
git clone https://opendev.org/$repo
popd
else
echo "Updating repo"
pushd $repo
git fetch -a
git pull
popd
fi
echo "Done"
done