Created
June 17, 2011 15:48
-
-
Save nbogie/1031677 to your computer and use it in GitHub Desktop.
script to syntax-check puppet .pp and .erb files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#Script to test puppet files have valid syntax. | |
#Intended for use with hudson/jenkins. | |
set -e | |
set -u | |
fail=0 | |
#TODO: Run these in parallel - we have 4 cores. | |
#TODO: Control the environment (through the config dir?). | |
# We want to parse for all environments. | |
# Is this being done, contrary to puppet report? | |
#TODO: Even with --ignoreimport, some may be pulling in others, | |
# meaning we're checking multiple times. | |
all_files=`find -name "*.pp" -o -name "*.erb"` | |
num_files=`echo $all_files | wc -w` | |
if [[ $num_files -eq "0" ]]; then | |
echo "ERROR: no .pp or .erb files found" | |
exit 1 | |
fi | |
echo "Checking $num_files *.pp and *.erb files for syntax errors." | |
echo "Puppet version is: `puppet --version`" | |
for x in $all_files; do | |
set +e | |
case $x in | |
*.pp ) | |
puppet --parseonly --ignoreimport --color=false $x ;; | |
*.erb ) | |
cat $x | erb -x -T - | ruby -c > /dev/null ;; | |
esac | |
rc=$? | |
set -e | |
if [[ $rc -ne 0 ]] ; then | |
fail=1 | |
echo "ERROR in $x (see above)" | |
fi | |
done | |
if [[ $fail -ne 0 ]] ; then | |
echo "FAIL: at least one file failed syntax check." | |
else | |
echo "SUCCESS: all .pp and *.erb files pass syntax check." | |
fi | |
exit $fail |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment