This repository has been archived by the owner on Jun 11, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathplay
executable file
·235 lines (202 loc) · 5.4 KB
/
play
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
#!/bin/bash
if ( [ ! -f Vagrantfile ] || [ ! -d toasters ] ) ; then
echo "You can play only in the puppet-playground ;-!"
echo "Change your cwd to your cloned puppet-playground directory and then run ./play"
exit 1
fi
toasterdir='toasters'
showhelp () {
cat << EOF
Play in Puppet Playground.
This command manages the playground: Vagrantfile, Puppetfile, modules/ and manifests/
Usage: play <action> [argument]
play status - Show playground status
play list - List the toasters available for installation
play install <toaster> - Install the specified toaster on the playground
play import <toaster_path> - Import a toaster from the specified path
play up [vm] - Startup Vagrant boxes.
play run [vm] - Run Puppet on the playground.
play clean - Clean up the playground (Puppet files, Vagrantfile not touched)
play setup default - Reinstall the default Vagrantfile (Puppet files not touched)
play setup example42 - Install Example42 modules (Vagrantfile and manifests not touched)
play forge <command> - Execute puppet module \$* commands to interact with PuppetForge
play puppi <command> - Execute puppi \$* commands on the running boxes
See README for more details.
EOF
}
SETCOLOR_NORMAL="echo -en \\033[0;39m"
SETCOLOR_TITLE="echo -en \\033[0;35m"
SETCOLOR_BOLD="echo -en \\033[0;1m"
echo_title () {
echo
$SETCOLOR_BOLD ; echo $1 ; $SETCOLOR_NORMAL
}
ask_confirm () {
cat << EOF
I'm going to wipe out the current Playground:
- modules/ directory
- manifests/ directory
- Puppetfile (if provided)
- Vagrantfile (if provided)
Do you really want to destroy the Playground? (y/N)
Answer NO if you have valuable changes in those files.
EOF
read answer
[ "x$answer" == "xy" ] || exit 3
}
list_toaster() {
echo_title "Available toasters for $0 install"
ls -1 $toasterdir
}
install_toaster() {
clean
if [[ $1 == git@github.com:* ]] || [[ $1 == http*://*github.com/* ]]; then
toaster_path="/tmp/$$"
git_url="true"
git clone $1 $toaster_path
else
toaster_path=$1
fi
echo_title "Installing toaster $toaster_path in the Playground"
[[ -f "${toaster_path}/Puppetfile" ]] && cp -f $toaster_path/Puppetfile Puppetfile
cp -fr $toaster_path/manifests .
[ -f $toaster_path/Vagrantfile ] && cp -f $toaster_path/Vagrantfile Vagrantfile
if [[ $git_url == "true" ]]; then
[ -f /tmp/$$ ] && echo "rm -rf /tmp/$$"
fi
if [[ -f Puppetfile ]]; then
echo_title "Running librarian-puppet install"
librarian-puppet install
fi
}
run_playground() {
echo_title "Running the playground (vagrant provision)"
vagrant provision $1
}
up_playground() {
echo_title "Starting up Vagrant VMs (vagrant up)"
vagrant up $1
}
run_puppi() {
echo_title "Running puppi $puppi_action on the active boxes of the Playground"
for vm in $(vagrant status | grep 'running$' | cut -d ' ' -f 1 ) ; do
echo_title "puppi check on $vm"
vagrant ssh $vm -c "sudo /usr/sbin/puppi $puppi_action"
done
}
run_forge() {
echo_title "Executing: puppet module $forge_action --modulepath modules/"
puppet module $forge_action --modulepath modules/
}
setup_example42() {
clean
echo_title "Setting up Example42 NetGen modules"
git clone --recursive https://github.com/example42/puppet-modules.git modules
}
setup_default() {
echo_title "Recovering default Vagrantfile"
cp -f Vagrantfile.default Vagrantfile
}
clean() {
ask_confirm
echo_title "Removing modules dir, manifests/init.pp and Puppetfile from the Playground"
rm -rf modules/
rm -rf manifests/
[[ -f Puppetfile ]] && rm -f Puppetfile
[[ -f Puppetfile.lock ]] && rm -f Puppetfile.lock
mkdir manifests
mkdir modules
touch manifests/init.pp
}
clean_librarian() {
if [[ -f Puppetfile ]]; then
echo_title "Executing librarian-puppet clean"
librarian-puppet clean
fi
}
status() {
echo_title "Modules status (puppet module list --modulepath=modules/) "
puppet module list --modulepath=modules/
if [[ -f Puppetfile ]]; then
echo_title "Modules status (librarian-puppet show) "
librarian-puppet show
fi
echo_title "Content of modules/ directory "
ls -l modules/
echo_title "Content of manifests/ directory "
ls -l manifests/
echo_title "Content of manifests/init.pp"
cat manifests/init.pp
echo_title "Vagrant Status"
vagrant status
}
while [ $# -gt 0 ]; do
case "$1" in
list)
action=$1
shift
;;
clean)
action=$1
shift
;;
status)
action=$1
shift
;;
install)
action=$1
toaster=$toasterdir/$2
shift 2
;;
import)
action=$1
toaster_path=$2
shift 2
;;
run)
action=$1
run_vm=$2
shift $#
;;
up)
action=$1
up_vm=$2
shift $#
;;
setup)
action=$1
setup_action=$2
shift 2
;;
puppi)
action=$1
shift
puppi_action=$*
shift $#
;;
forge)
action=$1
shift
forge_action=$*
shift $#
;;
*)
showhelp
exit
;;
esac
done
case $action in
list) list_toaster ;;
install) install_toaster $toaster ;;
import) install_toaster $toaster_path ;;
clean) clean ; clean_librarian ;;
status) status ;;
run ) run_playground $run_vm ;;
up ) up_playground $up_vm ;;
setup ) setup_$setup_action ;;
forge ) run_forge ;;
puppi ) run_puppi ;;
* ) showhelp ;;
esac