-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpuppet-validate.sh
executable file
·61 lines (52 loc) · 1.32 KB
/
puppet-validate.sh
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/bin/bash
#
#Modified from https://github.com/mig5/scripts/blob/master/puppet/puppet-test
#by Joe McWilliams [email protected]
PUPPET_DIR=$1
dependencies() {
# Make sure we were passed an argument
if [[ -z $PUPPET_DIR ]]; then
echo "You must provide a path to the puppet manifests!"
exit 1
fi
# Make sure that the directory passed as an argument, exists
if [ ! -d $PUPPET_DIR ]; then
echo "No such directory!"
exit 1
fi
}
pp_tests() {
# Test the .pp files for syntax errors
echo "===> Testing the syntax of puppet manifests"
for file in `find $PUPPET_DIR -type f -name "*.pp"`; do
echo "=====> Checking $file"
puppet parser validate $file || exit 1;
done
}
erb_tests() {
# Test the .erb template files for syntax errors
echo "===> Testing the syntax of puppet templates"
for file in `find $PUPPET_DIR -type f -name *.erb`; do
echo "=====> Checking $file"
erb -x -T '-' $file | ruby -c > /dev/null || exit 1;
done
}
check_result() {
# Check to see what the return code was from previous test
if [ $? -eq 0 ]; then
echo "Tests passed!"
else
echo "Looks like some tests failed. You'll need to check these."
fi
}
main() {
dependencies
pp_tests
check_result
erb_tests
check_result
if [ $? -eq 0 ]; then
echo "Yay! All tests passed."
fi
}
main