diff --git a/.ansible-lint b/.ansible-lint index 76369f8e..b8c91228 100644 --- a/.ansible-lint +++ b/.ansible-lint @@ -12,5 +12,12 @@ skip_list: - '306' - '106' - '208' + - fqcn-builtins # needs a lot of work + - yaml[line-length] # we use good taste with long lines + - yaml[truthy] # "yes" is ok use_default_rules: true verbosity: 1 + +# Local variables: +# mode: yaml +# End: diff --git a/test-requirements.txt b/test-requirements.txt index 8af6f097..008d9b3c 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -5,6 +5,6 @@ hacking>=4.0.0,<5.0.0 # Apache-2.0 # ansible-lint requires ansible>=2.9 -ansible>=2.9.0,<2.10 -ansible-lint>=5.0.0,<6.0.0 +ansible>=5,<6 +ansible-lint>=6,<7 bashate>=0.2 diff --git a/tools/ansible-lint-roles-cache.sh b/tools/ansible-lint-roles-cache.sh new file mode 100755 index 00000000..a3b93e3b --- /dev/null +++ b/tools/ansible-lint-roles-cache.sh @@ -0,0 +1,38 @@ +#!/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 diff --git a/tox.ini b/tox.ini index 20b3c0d6..16e560df 100644 --- a/tox.ini +++ b/tox.ini @@ -23,19 +23,16 @@ commands = [testenv:linters] whitelist_externals = bash -passenv = - # NOTE(pabelanger): if you'd like to run tox -elinters locally, you'll need - # to export ANSIBLE_ROLES_PATH pointing to the currect repos. - # see openstack-zuul-jobs-linters job for more information. - ANSIBLE_ROLES_PATH setenv = - ANSIBLE_LIBRARY= {toxinidir}/tests/fake-ansible + # NOTE(ianw) : In the gate job openstack-zuul-jobs-linters this is + # overridden to the Zuul checkouts of the projects. Locally, + # tools/ansible-lint-roles-cache.sh will populate these for the + # linter. + ANSIBLE_ROLES_PATH={env:ANSIBLE_ROLES_PATH:{toxinidir}/.cache/ansible-lint/opendev/base-jobs/roles:{toxinidir}/.cache/ansible-lint/opendev/system-config/roles:{toxinidir}/.cache/ansible-lint/zuul/zuul-jobs/roles:{toxinidir}/.cache/ansible-lint/openstack/openstack-zuul-jobs/roles} commands = flake8 {posargs} + {toxinidir}/tools/ansible-lint-roles-cache.sh ansible-lint - # Ansible Syntax Check - bash -c "cd playbooks; find . -type f -regex '.*.y[a]?ml' -exec \ - ansible-playbook --syntax-check -i {toxinidir}/tests/inventory \{\} + > /dev/null" [testenv:venv] commands = {posargs}