Skip to content

Instantly share code, notes, and snippets.

@tsantero
Created September 10, 2014 19:44
Show Gist options
  • Save tsantero/9e24d5969b618492b7e6 to your computer and use it in GitHub Desktop.
Save tsantero/9e24d5969b618492b7e6 to your computer and use it in GitHub Desktop.
#!/bin/bash
set +e
declare -i RESULT=0
GIT_DIFF_CMD="git diff HEAD~1 --name-only"
# Don't exit on error. Collect the errors instead.
YAML_PATH_LIST=`$GIT_DIFF_CMD |grep .yml`
# Check YAML files for syntax errors
echo 'YAML files to check syntax:'; echo "$YAML_PATH_LIST"; echo "";
for YAML_PATH in $YAML_PATH_LIST; do
ansible-playbook -i inventory --syntax-check ../${YAML_PATH};
RESULT+=$?
done
echo $RESULT "errors."
exit $RESULT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment