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