Due to popular demand (read: colleagues asking) I put this little script online which I originally found when googling the web for a way to reduce the count of commits that contain syntax errors in my Puppet recipes.
It will not find all errors (e.g. cyclic or broken requires) but it reduces the risk of overlooking copy&paste errors or typos a lot.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
#!/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 parser validate --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 |
Update: I found the original source on GitHub