|
1 # = Define puppi::project::dir |
|
2 # |
|
3 # This is a shortcut define to build a puppi project for a deploy based |
|
4 # on the syncronization of a directory. |
|
5 # It uses different "core" defines (puppi::project, puppi:deploy (many), |
|
6 # puppi::rollback (many)) to build a full featured template project for |
|
7 # automatic deployments. |
|
8 # If you need to customize it, either change the template defined here or |
|
9 # build up your own custom ones. |
|
10 # |
|
11 # == Variables: |
|
12 # |
|
13 # [*source*] |
|
14 # The full URL of the main file to retrieve. |
|
15 # Format should be in URI standard (http:// file:// ssh:// rsync://). |
|
16 # |
|
17 # [*deploy_root*] |
|
18 # The destination directory where the retrieved file(s) are deployed. |
|
19 # |
|
20 # [*init_source*] |
|
21 # (Optional) - The full URL to be used to retrieve, for the first time, |
|
22 # the project files. They are copied directly to the $deploy_root |
|
23 # Format should be in URI standard (http:// file:// ssh:// svn://). |
|
24 # |
|
25 # [*user*] |
|
26 # (Optional) - The user to be used for deploy operations. |
|
27 # |
|
28 # [*predeploy_customcommand*] |
|
29 # (Optional) - Full path with arguments of an eventual custom command to |
|
30 # execute before the deploy. The command is executed as $predeploy_user. |
|
31 # |
|
32 # [*predeploy_user*] |
|
33 # (Optional) - The user to be used to execute the $predeploy_customcommand. |
|
34 # By default is the same of $user. |
|
35 # |
|
36 # [*predeploy_priority*] |
|
37 # (Optional) - The priority (execution sequence number) that defines when, |
|
38 # during the deploy procedure, the $predeploy_customcommand is executed |
|
39 # Default: 39 (immediately before the copy of files on the deploy root). |
|
40 # |
|
41 # [*postdeploy_customcommand*] |
|
42 # (Optional) - Full path with arguments of an eventual custom command to |
|
43 # execute after the deploy. The command is executed as $postdeploy_user. |
|
44 # |
|
45 # [*postdeploy_user*] |
|
46 # (Optional) - The user to be used to execute the $postdeploy_customcommand. |
|
47 # By default is the same of $user. |
|
48 # |
|
49 # [*postdeploy_priority*] |
|
50 # (Optional) - The priority (execution sequence number) that defines when, |
|
51 # during the deploy procedure, the $postdeploy_customcommand is executed |
|
52 # Default: 41 (immediately after the copy of files on the deploy root). |
|
53 # |
|
54 # [*init_script*] |
|
55 # (Optional - Obsolete) - The name (ex: tomcat) of the init script of your |
|
56 # Application server. If you define it, the AS is stopped and then started |
|
57 # during deploy. This option is deprecated, you can use $disable_services |
|
58 # for the same functionality |
|
59 # |
|
60 # [*disable_services*] |
|
61 # (Optional) - The names (space separated) of the services you might want to |
|
62 # stop during deploy. By default is blank. Example: "apache puppet monit". |
|
63 # |
|
64 # [*firewall_src_ip*] |
|
65 # (Optional) - The IP address of a loadbalancer you might want to block out |
|
66 # during a deploy. |
|
67 # |
|
68 # [*firewall_dst_port*] |
|
69 # (Optional) - The local port to block from the loadbalancer during deploy |
|
70 # (Default all). |
|
71 # |
|
72 # [*firewall_delay*] |
|
73 # (Optional) - A delay time in seconds to wait after the block of |
|
74 # $firewall_src_ip. Should be at least as long as the loadbalancer check |
|
75 # interval for the services stopped during deploy (Default: 1). |
|
76 # |
|
77 # [*report_email*] |
|
78 # (Optional) - The (space separated) email(s) to notify of deploy/rollback |
|
79 # operations. If none is specified, no email is sent. |
|
80 # |
|
81 # [*backup_rsync_options*] |
|
82 # (Optional) - The extra options to pass to rsync for backup operations. Use |
|
83 # it, for example, to exclude directories that you don't want to archive. |
|
84 # IE: "--exclude .snapshot --exclude cache --exclude www/cache". |
|
85 # |
|
86 # [*backup_retention*] |
|
87 # (Optional) - Number of backup archives to keep. (Default 5). |
|
88 # Lower the default value if your backups are too large and may fill up the |
|
89 # filesystem. |
|
90 # |
|
91 # [*run_checks*] |
|
92 # (Optional) - If you want to run local puppi checks before and after the |
|
93 # deploy procedure. Default: "true". |
|
94 # |
|
95 # [*skip_predeploy*] |
|
96 # For large data to deploy predeploy copy in /tmp/puppi might full the |
|
97 # filesystem. Set to "yes" to deploy directly to $deploy_root. Default: no |
|
98 # (files are first predeployed in /tmp/puppi then copied to $deploy_root) |
|
99 # |
|
100 # [*auto_deploy*] |
|
101 # (Optional) - If you want to automatically run this puppi deploy when |
|
102 # Puppet runs. Default: 'false' |
|
103 # |
|
104 define puppi::project::dir ( |
|
105 $source, |
|
106 $deploy_root, |
|
107 $init_source = '', |
|
108 $user = 'root', |
|
109 $predeploy_customcommand = '', |
|
110 $predeploy_user = '', |
|
111 $predeploy_priority = '39', |
|
112 $postdeploy_customcommand = '', |
|
113 $postdeploy_user = '', |
|
114 $postdeploy_priority = '41', |
|
115 $init_script = '', |
|
116 $disable_services = '', |
|
117 $firewall_src_ip = '', |
|
118 $firewall_dst_port = '0', |
|
119 $firewall_delay = '1', |
|
120 $report_email = '', |
|
121 $backup_rsync_options = '--exclude .snapshot', |
|
122 $backup_retention = '5', |
|
123 $run_checks = true, |
|
124 $skip_predeploy = false, |
|
125 $auto_deploy = false, |
|
126 $enable = true ) { |
|
127 |
|
128 require puppi |
|
129 require puppi::params |
|
130 |
|
131 # Set default values |
|
132 $predeploy_real_user = $predeploy_user ? { |
|
133 '' => $user, |
|
134 default => $predeploy_user, |
|
135 } |
|
136 |
|
137 $postdeploy_real_user = $postdeploy_user ? { |
|
138 '' => $user, |
|
139 default => $postdeploy_user, |
|
140 } |
|
141 |
|
142 $bool_run_checks = any2bool($run_checks) |
|
143 $bool_skip_predeploy = any2bool($skip_predeploy) |
|
144 $bool_auto_deploy = any2bool($auto_deploy) |
|
145 |
|
146 ### CREATE PROJECT |
|
147 puppi::project { $name: |
|
148 enable => $enable , |
|
149 } |
|
150 |
|
151 |
|
152 ### INIT SEQUENCE |
|
153 if ($init_source != '') { |
|
154 puppi::initialize { "${name}-Deploy_Files": |
|
155 priority => '40' , |
|
156 command => 'get_file.sh' , |
|
157 arguments => "-s ${init_source} -d ${deploy_root}" , |
|
158 user => $user , |
|
159 project => $name , |
|
160 enable => $enable , |
|
161 } |
|
162 } |
|
163 |
|
164 |
|
165 ### DEPLOY SEQUENCE |
|
166 if ($bool_run_checks == true) { |
|
167 puppi::deploy { "${name}-Run_PRE-Checks": |
|
168 priority => '10' , |
|
169 command => 'check_project.sh' , |
|
170 arguments => $name , |
|
171 user => 'root' , |
|
172 project => $name , |
|
173 enable => $enable , |
|
174 } |
|
175 } |
|
176 |
|
177 if ($bool_skip_predeploy == false) { |
|
178 puppi::deploy { "${name}-Sync_Files": |
|
179 priority => '20' , |
|
180 command => 'get_file.sh' , |
|
181 arguments => "-s ${source} -t dir" , |
|
182 user => 'root' , |
|
183 project => $name , |
|
184 enable => $enable , |
|
185 } |
|
186 } |
|
187 |
|
188 if ($firewall_src_ip != '') { |
|
189 puppi::deploy { "${name}-Load_Balancer_Block": |
|
190 priority => '25' , |
|
191 command => 'firewall.sh' , |
|
192 arguments => "${firewall_src_ip} ${firewall_dst_port} on ${firewall_delay}" , |
|
193 user => 'root', |
|
194 project => $name , |
|
195 enable => $enable , |
|
196 } |
|
197 } |
|
198 |
|
199 puppi::deploy { "${name}-Backup_existing_Files": |
|
200 priority => '30' , |
|
201 command => 'archive.sh' , |
|
202 arguments => "-b ${deploy_root} -o '${backup_rsync_options}' -n ${backup_retention}" , |
|
203 user => 'root' , |
|
204 project => $name , |
|
205 enable => $enable , |
|
206 } |
|
207 |
|
208 if ($disable_services != '') { |
|
209 puppi::deploy { "${name}-Disable_extra_services": |
|
210 priority => '36' , |
|
211 command => 'service.sh' , |
|
212 arguments => "stop ${disable_services}" , |
|
213 user => 'root', |
|
214 project => $name , |
|
215 enable => $enable , |
|
216 } |
|
217 } |
|
218 |
|
219 if ($init_script != '') { |
|
220 puppi::deploy { "${name}-Service_stop": |
|
221 priority => '38' , |
|
222 command => 'service.sh' , |
|
223 arguments => "stop ${init_script}" , |
|
224 user => 'root', |
|
225 project => $name , |
|
226 enable => $enable , |
|
227 } |
|
228 } |
|
229 |
|
230 if ($predeploy_customcommand != '') { |
|
231 puppi::deploy { "${name}-Run_Custom_PreDeploy_Script": |
|
232 priority => $predeploy_priority , |
|
233 command => 'execute.sh' , |
|
234 arguments => $predeploy_customcommand , |
|
235 user => $predeploy_real_user , |
|
236 project => $name , |
|
237 enable => $enable , |
|
238 } |
|
239 } |
|
240 |
|
241 # Here is done the deploy on $deploy_root |
|
242 if ($bool_skip_predeploy == false) { |
|
243 puppi::deploy { "${name}-Deploy": |
|
244 priority => '40' , |
|
245 command => 'deploy.sh' , |
|
246 arguments => $deploy_root , |
|
247 user => $user , |
|
248 project => $name , |
|
249 enable => $enable , |
|
250 } |
|
251 } |
|
252 |
|
253 if ($bool_skip_predeploy == true) { |
|
254 puppi::deploy { "${name}-Deploy": |
|
255 priority => '40' , |
|
256 command => 'get_file.sh' , |
|
257 arguments => "-s ${source} -d ${deploy_root}" , |
|
258 user => $user , |
|
259 project => $name , |
|
260 enable => $enable , |
|
261 } |
|
262 } |
|
263 # End deploy |
|
264 |
|
265 if ($postdeploy_customcommand != '') { |
|
266 puppi::deploy { "${name}-Run_Custom_PostDeploy_Script": |
|
267 priority => $postdeploy_priority , |
|
268 command => 'execute.sh' , |
|
269 arguments => $postdeploy_customcommand , |
|
270 user => $postdeploy_real_user , |
|
271 project => $name , |
|
272 enable => $enable , |
|
273 } |
|
274 } |
|
275 |
|
276 if ($init_script != '') { |
|
277 puppi::deploy { "${name}-Service_start": |
|
278 priority => '42' , |
|
279 command => 'service.sh' , |
|
280 arguments => "start ${init_script}" , |
|
281 user => 'root', |
|
282 project => $name , |
|
283 enable => $enable , |
|
284 } |
|
285 } |
|
286 |
|
287 if ($disable_services != '') { |
|
288 puppi::deploy { "${name}-Enable_extra_services": |
|
289 priority => '44' , |
|
290 command => 'service.sh' , |
|
291 arguments => "start ${disable_services}" , |
|
292 user => 'root', |
|
293 project => $name , |
|
294 enable => $enable , |
|
295 } |
|
296 } |
|
297 |
|
298 if ($firewall_src_ip != '') { |
|
299 puppi::deploy { "${name}-Load_Balancer_Unblock": |
|
300 priority => '46' , |
|
301 command => 'firewall.sh' , |
|
302 arguments => "${firewall_src_ip} ${firewall_dst_port} off 0" , |
|
303 user => 'root', |
|
304 project => $name , |
|
305 enable => $enable , |
|
306 } |
|
307 } |
|
308 |
|
309 if ($bool_run_checks == true) { |
|
310 puppi::deploy { "${name}-Run_POST-Checks": |
|
311 priority => '80' , |
|
312 command => 'check_project.sh' , |
|
313 arguments => $name , |
|
314 user => 'root' , |
|
315 project => $name , |
|
316 enable => $enable , |
|
317 } |
|
318 } |
|
319 |
|
320 |
|
321 ### ROLLBACK SEQUENCE |
|
322 |
|
323 if ($firewall_src_ip != '') { |
|
324 puppi::rollback { "${name}-Load_Balancer_Block": |
|
325 priority => '25' , |
|
326 command => 'firewall.sh' , |
|
327 arguments => "${firewall_src_ip} ${firewall_dst_port} on ${firewall_delay}" , |
|
328 user => 'root', |
|
329 project => $name , |
|
330 enable => $enable , |
|
331 } |
|
332 } |
|
333 |
|
334 if ($disable_services != '') { |
|
335 puppi::rollback { "${name}-Disable_extra_services": |
|
336 priority => '37' , |
|
337 command => 'service.sh' , |
|
338 arguments => "stop ${disable_services}" , |
|
339 user => 'root', |
|
340 project => $name , |
|
341 enable => $enable , |
|
342 } |
|
343 } |
|
344 |
|
345 if ($init_script != '') { |
|
346 puppi::rollback { "${name}-Service_stop": |
|
347 priority => '38' , |
|
348 command => 'service.sh' , |
|
349 arguments => "stop ${init_script}" , |
|
350 user => 'root', |
|
351 project => $name , |
|
352 enable => $enable , |
|
353 } |
|
354 } |
|
355 |
|
356 if ($predeploy_customcommand != '') { |
|
357 puppi::rollback { "${name}-Run_Custom_PreDeploy_Script": |
|
358 priority => $predeploy_priority , |
|
359 command => 'execute.sh' , |
|
360 arguments => $predeploy_customcommand , |
|
361 user => $predeploy_real_user , |
|
362 project => $name , |
|
363 enable => $enable , |
|
364 } |
|
365 } |
|
366 |
|
367 puppi::rollback { "${name}-Recover_Files_To_Deploy": |
|
368 priority => '40' , |
|
369 command => 'archive.sh' , |
|
370 arguments => "-r ${deploy_root} -o '${backup_rsync_options}'" , |
|
371 user => $user , |
|
372 project => $name , |
|
373 enable => $enable , |
|
374 } |
|
375 |
|
376 if ($postdeploy_customcommand != '') { |
|
377 puppi::rollback { "${name}-Run_Custom_PostDeploy_Script": |
|
378 priority => $postdeploy_priority , |
|
379 command => 'execute.sh' , |
|
380 arguments => $postdeploy_customcommand , |
|
381 user => $postdeploy_real_user , |
|
382 project => $name , |
|
383 enable => $enable , |
|
384 } |
|
385 } |
|
386 |
|
387 if ($init_script != '') { |
|
388 puppi::rollback { "${name}-Service_start": |
|
389 priority => '42' , |
|
390 command => 'service.sh' , |
|
391 arguments => "start ${init_script}" , |
|
392 user => 'root', |
|
393 project => $name , |
|
394 enable => $enable , |
|
395 } |
|
396 } |
|
397 |
|
398 if ($disable_services != '') { |
|
399 puppi::rollback { "${name}-Enable_extra_services": |
|
400 priority => '44' , |
|
401 command => 'service.sh' , |
|
402 arguments => "start ${disable_services}" , |
|
403 user => 'root', |
|
404 project => $name , |
|
405 enable => $enable , |
|
406 } |
|
407 } |
|
408 |
|
409 if ($firewall_src_ip != '') { |
|
410 puppi::rollback { "${name}-Load_Balancer_Unblock": |
|
411 priority => '46' , |
|
412 command => 'firewall.sh' , |
|
413 arguments => "${firewall_src_ip} ${firewall_dst_port} off 0" , |
|
414 user => 'root', |
|
415 project => $name , |
|
416 enable => $enable , |
|
417 } |
|
418 } |
|
419 |
|
420 if ($bool_run_checks == true) { |
|
421 puppi::rollback { "${name}-Run_POST-Checks": |
|
422 priority => '80' , |
|
423 command => 'check_project.sh' , |
|
424 arguments => $name , |
|
425 user => 'root' , |
|
426 project => $name , |
|
427 enable => $enable , |
|
428 } |
|
429 } |
|
430 |
|
431 |
|
432 ### REPORTING |
|
433 |
|
434 if ($report_email != '') { |
|
435 puppi::report { "${name}-Mail_Notification": |
|
436 priority => '20' , |
|
437 command => 'report_mail.sh' , |
|
438 arguments => $report_email , |
|
439 user => 'root', |
|
440 project => $name , |
|
441 enable => $enable , |
|
442 } |
|
443 } |
|
444 |
|
445 ### AUTO DEPLOY DURING PUPPET RUN |
|
446 if ($bool_auto_deploy == true) { |
|
447 puppi::run { $name: } |
|
448 } |
|
449 |
|
450 } |