Skip to content

Instantly share code, notes, and snippets.

@xen0l
Created October 20, 2016 15:01
Show Gist options
  • Save xen0l/0c174fe440e025838837bfb5def356ab to your computer and use it in GitHub Desktop.
Save xen0l/0c174fe440e025838837bfb5def356ab to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# Colors
NOCOLOR='\e[0m'
BLACK='\e[0;30m'
RED='\e[0;31m'
GREEN='\e[0;32m'
YELLOW='\e[0;33m'
BLUE='\e[0;34m'
PURPLE='\e[0;35m'
CYAN='\e[0;36m'
WHITE='\e[0;37m'
__DIR__="$(cd "$(dirname "${0}")"; pwd)"
__BASE__="$(basename "${0}")"
__FILE__="${__DIR__}/${__BASE__}"
echo "###############################################################"
echo "Build Information:"
echo "Directory: ${__DIR__}"
echo "Filename: ${__FILE__}"
echo "Version Information:"
echo "Ansible Version: $(ansible --version | head -1 | awk '{print $2}')"
echo "Ansible Playbook Version: $(ansible-playbook --version | head -1 | awk '{print $2}')"
echo "Ansible Lint Version: $(ansible-lint --version | awk '{print $2}')"
echo "Operating System: $(uname -s)"
echo "Kernel: $(uname -a)"
echo "###############################################################"
echo "### Starting tests"
echo "### Checking for syntax errors"
for playbook in $(find . -maxdepth 1 -name '*.yml' -exec basename {} \;); do
printf "%-50s\t\t\t\t" ${playbook}
ansible-playbook -i production --syntax-check "${playbook}" &> /dev/null
if [[ $? -eq 0 ]]; then
printf "${GREEN}OK${NOCOLOR}\n"
else
printf "${RED}FAILED\n"
ansible-playbook -i production --syntax-check "${playbook}"
printf "${NOCOLOR}\n"
fi
done
echo -e "\n### Checking for lint errors"
for playbook in $(find . -maxdepth 1 -name '*.yml' -exec basename {} \;); do
printf "%-50s\t\t\t\t" ${playbook}
ansible-lint "${playbook}" &> /dev/null
if [[ $? -eq 0 ]]; then
printf "${GREEN}OK${NOCOLOR}\n"
else
printf "${RED}%s\n"
ansible-lint "${playbook}"
printf "${NOCOLOR}\n"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment