engine: Enable ansible-lint 58/3058/3
authorFatih Degirmenci <fdegir@gmail.com>
Wed, 4 Dec 2019 09:33:11 +0000 (10:33 +0100)
committerFatih Degirmenci <fdegir@gmail.com>
Wed, 4 Dec 2019 09:59:29 +0000 (10:59 +0100)
Change-Id: I365c2cb3aefd63a90d016244003390169ffb8ad7

jjb/cloud-infra/scripts/cloud-infra-ansible-lint.sh

index db8fba239bb47e95d2a5d76f35bd7c67aa0e452b..ece055e17bce337f6abbe60b45ea4380bcc97402 100644 (file)
 # SPDX-License-Identifier: Apache-2.0
 # ============LICENSE_END=========================================================
 
-set -o errexit
-set -o nounset
-set -o pipefail
+# source engine-vars so we can install the correct versions of
+# pip, ansible, and ansible-lint
+source $WORKSPACE/engine/config/engine-vars
+
+# 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
 
 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 "----------------------------------------------------"
+
+# the locations of the engine playbooks
+playbooks_dir=(engine/playbooks engine/provisioner/bifrost/playbooks engine/provisioner/heat/playbooks \
+    engine/installer/kolla/playbooks engine/installer/kubespray/playbooks)
+
+# 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
+for dir in ${playbooks_dir[@]}; do
+  for play in $(ls ${WORKSPACE}/${dir}/*.yml); do
+    echo "--> Checking '${play}' playbook..."
+    ansible-lint --nocolor ${play}
+    lint_exit_code=$?
+    if [[ $lint_exit_code != 0 ]]; then
+        exit_code=$lint_exit_code
+    else
+        echo [OK]
+    fi
+    echo
+  done
+done
+echo "----------------------------------------------------"
+echo "Info: Done"
+exit $exit_code
 
 # vim: set ts=2 sw=2 expandtab: