X-Git-Url: https://gerrit.nordix.org/gitweb?a=blobdiff_plain;f=jjb%2Fcloud-infra%2Fscripts%2Fcloud-infra-ansible-lint.sh;h=03f32ee63eea51737a6fced1c30d6758d0f31914;hb=refs%2Fchanges%2F17%2F3217%2F2;hp=db8fba239bb47e95d2a5d76f35bd7c67aa0e452b;hpb=0efc1c9a17f5883596be4b8e9263b674c1fb4406;p=infra%2Fcicd.git diff --git a/jjb/cloud-infra/scripts/cloud-infra-ansible-lint.sh b/jjb/cloud-infra/scripts/cloud-infra-ansible-lint.sh index db8fba23..03f32ee6 100644 --- a/jjb/cloud-infra/scripts/cloud-infra-ansible-lint.sh +++ b/jjb/cloud-infra/scripts/cloud-infra-ansible-lint.sh @@ -18,11 +18,54 @@ # SPDX-License-Identifier: Apache-2.0 # ============LICENSE_END========================================================= -set -o errexit -set -o nounset -set -o pipefail +# source engine-vars.sh so we can install the correct versions of +# pip, ansible, and ansible-lint +source $WORKSPACE/engine/config/engine-vars.sh + +# install dependencies +sudo apt update > /dev/null 2>&1 +sudo apt install -y -q=3 gcc libffi-dev libssl-dev lsb-release libpython3-dev \ + python3-minimal python3-pip python3-yaml virtualenv > /dev/null 2>&1 + +# override ENGINE_ANSIBLE_LINT_VERSION locally while ansible-lint patch is still open +export ENGINE_ANSIBLE_LINT_VERSION=4.1.0 cd $WORKSPACE -echo "Hello, World!" +echo "Info: Install pip==$ENGINE_PIP_VERSION ansible==$ENGINE_ANSIBLE_VERSION and ansible-lint==$ENGINE_ANSIBLE_LINT_VERSION" +echo "----------------------------------------------------" + +# install pip, ansible, and ansible-lint in venv +export ANSIBLE_VENV=$WORKSPACE/.venv +virtualenv -p python3 --quiet --no-site-packages ${ANSIBLE_VENV} +source ${ANSIBLE_VENV}/bin/activate +pip -q install --upgrade pip==$ENGINE_PIP_VERSION +pip -q install --upgrade virtualenv pip setuptools shade \ + ansible==$ENGINE_ANSIBLE_VERSION ansible-lint==$ENGINE_ANSIBLE_LINT_VERSION + +echo "----------------------------------------------------" +echo "Info: Done" +echo "Info: Run ansible-lint on playbooks" +echo "----------------------------------------------------" + +# set exit_code so we exit ourselves rather than ansible-lint bailing out without +# verifying all the playbooks +declare -i exit_code=0 + +# lint the playbooks +cd $WORKSPACE/engine +for playbook in $(find . -type f -name *.yml | sort); do + echo "--> Checking '${playbook}' playbook..." + ansible-lint --nocolor ${playbook} + lint_exit_code=$? + if [[ $lint_exit_code != 0 ]]; then + exit_code=$lint_exit_code + else + echo [OK] + fi + echo +done +echo "----------------------------------------------------" +echo "Info: Done" +exit $exit_code # vim: set ts=2 sw=2 expandtab: