|
1 # = Define puppi::project::yum |
|
2 # |
|
3 # This is a shortcut define to build a puppi project for the |
|
4 # deploy of applications packaged as rpm and retrievable via yum |
|
5 # |
|
6 # It uses different "core" defines (puppi::project, puppi:deploy (many), |
|
7 # puppi::rollback (many)) to build a full featured template project for |
|
8 # automatic deployments. |
|
9 # If you need to customize it, either change the template defined here or |
|
10 # build up your own custom ones. |
|
11 # |
|
12 # == Variables: |
|
13 # |
|
14 # [*rpm*] |
|
15 # The name of the rpm to install |
|
16 # |
|
17 # [*rpm_version*] |
|
18 # (Optional) - The version to install (default: latest) |
|
19 # |
|
20 # [*install_root*] |
|
21 # (Optional) - The rpm installation root (default: / ) |
|
22 # |
|
23 # [*predeploy_customcommand*] |
|
24 # (Optional) - Full path with arguments of an eventual custom command to |
|
25 # execute before the deploy. The command is executed as $predeploy_user. |
|
26 # |
|
27 # [*predeploy_user*] |
|
28 # (Optional) - The user to be used to execute the $predeploy_customcommand. |
|
29 # By default is the same of $user. |
|
30 # |
|
31 # [*predeploy_priority*] |
|
32 # (Optional) - The priority (execution sequence number) that defines when, |
|
33 # during the deploy procedure, the $predeploy_customcommand is executed |
|
34 # Default: 39 (immediately before the copy of files on the deploy root). |
|
35 # |
|
36 # [*postdeploy_customcommand*] |
|
37 # (Optional) - Full path with arguments of an eventual custom command to |
|
38 # execute after the deploy. The command is executed as $postdeploy_user. |
|
39 # |
|
40 # [*postdeploy_user*] |
|
41 # (Optional) - The user to be used to execute the $postdeploy_customcommand. |
|
42 # By default is the same of $user. |
|
43 # |
|
44 # [*postdeploy_priority*] |
|
45 # (Optional) - The priority (execution sequence number) that defines when, |
|
46 # during the deploy procedure, the $postdeploy_customcommand is executed |
|
47 # Default: 41 (immediately after the copy of files on the deploy root). |
|
48 # |
|
49 # [*disable_services*] |
|
50 # (Optional) - The names (space separated) of the services you might want to |
|
51 # stop during deploy. By default is blank. Example: "apache puppet monit". |
|
52 # |
|
53 # [*firewall_src_ip*] |
|
54 # (Optional) - The IP address of a loadbalancer you might want to block out |
|
55 # during a deploy. |
|
56 # |
|
57 # [*firewall_dst_port*] |
|
58 # (Optional) - The local port to block from the loadbalancer during deploy |
|
59 # (Default all). |
|
60 # |
|
61 # [*firewall_delay*] |
|
62 # (Optional) - A delay time in seconds to wait after the block of |
|
63 # $firewall_src_ip. Should be at least as long as the loadbalancer check |
|
64 # interval for the services stopped during deploy (Default: 1). |
|
65 # |
|
66 # [*report_email*] |
|
67 # (Optional) - The (space separated) email(s) to notify of deploy/rollback |
|
68 # operations. If none is specified, no email is sent. |
|
69 # |
|
70 # [*run_checks*] |
|
71 # (Optional) - If you want to run local puppi checks before and after the |
|
72 # deploy procedure. Default: "true". |
|
73 # |
|
74 # [*checks_required*] |
|
75 # (Optional) - Set to "true" if you want to block the installation if |
|
76 # preliminary checks fail. Default: "false" |
|
77 # |
|
78 # [*always_deploy*] |
|
79 # (Optional) - If you always deploy what has been downloaded. Default="yes", |
|
80 # if set to "no" a checksum is made between the files previously downloaded |
|
81 # and the new files. If they are the same the deploy is not done. |
|
82 # |
|
83 # [*auto_deploy*] |
|
84 # (Optional) - If you want to automatically run this puppi deploy when |
|
85 # Puppet runs. Default: 'false' |
|
86 # |
|
87 define puppi::project::yum ( |
|
88 $rpm, |
|
89 $rpm_version = 'latest', |
|
90 $install_root = '/', |
|
91 $predeploy_customcommand = '', |
|
92 $predeploy_user = '', |
|
93 $predeploy_priority = '39', |
|
94 $postdeploy_customcommand = '', |
|
95 $postdeploy_user = '', |
|
96 $postdeploy_priority = '41', |
|
97 $disable_services = '', |
|
98 $firewall_src_ip = '', |
|
99 $firewall_dst_port = '0', |
|
100 $firewall_delay = '1', |
|
101 $report_email = '', |
|
102 $run_checks = true, |
|
103 $checks_required = false, |
|
104 $always_deploy = true, |
|
105 $auto_deploy = false, |
|
106 $enable = true ) { |
|
107 |
|
108 require puppi |
|
109 require puppi::params |
|
110 |
|
111 # Set default values |
|
112 $predeploy_real_user = $predeploy_user ? { |
|
113 '' => 'root', |
|
114 default => $predeploy_user, |
|
115 } |
|
116 |
|
117 $postdeploy_real_user = $postdeploy_user ? { |
|
118 '' => 'root', |
|
119 default => $postdeploy_user, |
|
120 } |
|
121 |
|
122 $real_always_deploy = any2bool($always_deploy) ? { |
|
123 true => 'yes', |
|
124 default => 'no', |
|
125 } |
|
126 |
|
127 $real_checks_required = any2bool($checks_required) ? { |
|
128 true => 'yes', |
|
129 default => 'no', |
|
130 } |
|
131 |
|
132 $bool_run_checks = any2bool($run_checks) |
|
133 $bool_auto_deploy = any2bool($auto_deploy) |
|
134 |
|
135 ### CREATE PROJECT |
|
136 puppi::project { $name: |
|
137 enable => $enable , |
|
138 } |
|
139 |
|
140 ### DEPLOY SEQUENCE |
|
141 if ($bool_run_checks == true) { |
|
142 puppi::deploy { "${name}-Run_PRE-Checks": |
|
143 priority => '10' , |
|
144 command => 'check_project.sh' , |
|
145 arguments => "${name} ${real_checks_required}", |
|
146 user => 'root' , |
|
147 project => $name , |
|
148 enable => $enable , |
|
149 } |
|
150 } |
|
151 |
|
152 if ($firewall_src_ip != '') { |
|
153 puppi::deploy { "${name}-Load_Balancer_Block": |
|
154 priority => '25' , |
|
155 command => 'firewall.sh' , |
|
156 arguments => "${firewall_src_ip} ${firewall_dst_port} on ${firewall_delay}" , |
|
157 user => 'root', |
|
158 project => $name , |
|
159 enable => $enable , |
|
160 } |
|
161 } |
|
162 |
|
163 if ($disable_services != '') { |
|
164 puppi::deploy { "${name}-Disable_extra_services": |
|
165 priority => '36' , |
|
166 command => 'service.sh' , |
|
167 arguments => "stop ${disable_services}" , |
|
168 user => 'root', |
|
169 project => $name , |
|
170 enable => $enable , |
|
171 } |
|
172 } |
|
173 |
|
174 if ($predeploy_customcommand != '') { |
|
175 puppi::deploy { "${name}-Run_Custom_PreDeploy_Script": |
|
176 priority => $predeploy_priority , |
|
177 command => 'execute.sh' , |
|
178 arguments => $predeploy_customcommand , |
|
179 user => $predeploy_real_user , |
|
180 project => $name , |
|
181 enable => $enable , |
|
182 } |
|
183 } |
|
184 |
|
185 # Here is done the deploy on $deploy_root |
|
186 puppi::deploy { "${name}-Deploy": |
|
187 priority => '40' , |
|
188 command => 'yum.sh' , |
|
189 arguments => "-a deploy -n ${rpm} -r ${install_root} -v ${rpm_version}" , |
|
190 user => root , |
|
191 project => $name , |
|
192 enable => $enable , |
|
193 } |
|
194 |
|
195 if ($postdeploy_customcommand != '') { |
|
196 puppi::deploy { "${name}-Run_Custom_PostDeploy_Script": |
|
197 priority => $postdeploy_priority , |
|
198 command => 'execute.sh' , |
|
199 arguments => $postdeploy_customcommand , |
|
200 user => $postdeploy_real_user , |
|
201 project => $name , |
|
202 enable => $enable , |
|
203 } |
|
204 } |
|
205 |
|
206 if ($disable_services != '') { |
|
207 puppi::deploy { "${name}-Enable_extra_services": |
|
208 priority => '44' , |
|
209 command => 'service.sh' , |
|
210 arguments => "start ${disable_services}" , |
|
211 user => 'root', |
|
212 project => $name , |
|
213 enable => $enable , |
|
214 } |
|
215 } |
|
216 |
|
217 if ($firewall_src_ip != '') { |
|
218 puppi::deploy { "${name}-Load_Balancer_Unblock": |
|
219 priority => '46' , |
|
220 command => 'firewall.sh' , |
|
221 arguments => "${firewall_src_ip} ${firewall_dst_port} off 0" , |
|
222 user => 'root', |
|
223 project => $name , |
|
224 enable => $enable , |
|
225 } |
|
226 } |
|
227 |
|
228 if ($bool_run_checks == true) { |
|
229 puppi::deploy { "${name}-Run_POST-Checks": |
|
230 priority => '80' , |
|
231 command => 'check_project.sh' , |
|
232 arguments => $name , |
|
233 user => 'root' , |
|
234 project => $name , |
|
235 enable => $enable , |
|
236 } |
|
237 } |
|
238 |
|
239 |
|
240 ### ROLLBACK PROCEDURE |
|
241 |
|
242 if ($firewall_src_ip != '') { |
|
243 puppi::rollback { "${name}-Load_Balancer_Block": |
|
244 priority => '25' , |
|
245 command => 'firewall.sh' , |
|
246 arguments => "${firewall_src_ip} ${firewall_dst_port} on ${firewall_delay}" , |
|
247 user => 'root', |
|
248 project => $name , |
|
249 enable => $enable , |
|
250 } |
|
251 } |
|
252 |
|
253 if ($disable_services != '') { |
|
254 puppi::rollback { "${name}-Disable_extra_services": |
|
255 priority => '37' , |
|
256 command => 'service.sh' , |
|
257 arguments => "stop ${disable_services}" , |
|
258 user => 'root', |
|
259 project => $name , |
|
260 enable => $enable , |
|
261 } |
|
262 } |
|
263 |
|
264 if ($predeploy_customcommand != '') { |
|
265 puppi::rollback { "${name}-Run_Custom_PreDeploy_Script": |
|
266 priority => $predeploy_priority , |
|
267 command => 'execute.sh' , |
|
268 arguments => $predeploy_customcommand , |
|
269 user => $predeploy_real_user , |
|
270 project => $name , |
|
271 enable => $enable , |
|
272 } |
|
273 } |
|
274 |
|
275 puppi::rollback { "${name}-Rollback": |
|
276 priority => '40' , |
|
277 command => 'yum.sh' , |
|
278 arguments => "-a rollback -n ${rpm} -r ${install_root} -v ${rpm_version}" , |
|
279 user => 'root' , |
|
280 project => $name , |
|
281 enable => $enable , |
|
282 } |
|
283 |
|
284 if ($postdeploy_customcommand != '') { |
|
285 puppi::rollback { "${name}-Run_Custom_PostDeploy_Script": |
|
286 priority => $postdeploy_priority , |
|
287 command => 'execute.sh' , |
|
288 arguments => $postdeploy_customcommand , |
|
289 user => $postdeploy_real_user , |
|
290 project => $name , |
|
291 enable => $enable , |
|
292 } |
|
293 } |
|
294 |
|
295 if ($disable_services != '') { |
|
296 puppi::rollback { "${name}-Enable_extra_services": |
|
297 priority => '44' , |
|
298 command => 'service.sh' , |
|
299 arguments => "start ${disable_services}" , |
|
300 user => 'root', |
|
301 project => $name , |
|
302 enable => $enable , |
|
303 } |
|
304 } |
|
305 |
|
306 if ($firewall_src_ip != '') { |
|
307 puppi::rollback { "${name}-Load_Balancer_Unblock": |
|
308 priority => '46' , |
|
309 command => 'firewall.sh' , |
|
310 arguments => "${firewall_src_ip} ${firewall_dst_port} off 0" , |
|
311 user => 'root', |
|
312 project => $name , |
|
313 enable => $enable , |
|
314 } |
|
315 } |
|
316 |
|
317 if ($bool_run_checks == true) { |
|
318 puppi::rollback { "${name}-Run_POST-Checks": |
|
319 priority => '80' , |
|
320 command => 'check_project.sh' , |
|
321 arguments => $name , |
|
322 user => 'root' , |
|
323 project => $name , |
|
324 enable => $enable , |
|
325 } |
|
326 } |
|
327 |
|
328 |
|
329 ### REPORTING |
|
330 |
|
331 if ($report_email != '') { |
|
332 puppi::report { "${name}-Mail_Notification": |
|
333 priority => '20' , |
|
334 command => 'report_mail.sh' , |
|
335 arguments => $report_email , |
|
336 user => 'root', |
|
337 project => $name , |
|
338 enable => $enable , |
|
339 } |
|
340 } |
|
341 |
|
342 ### AUTO DEPLOY DURING PUPPET RUN |
|
343 if ($bool_auto_deploy == true) { |
|
344 puppi::run { $name: } |
|
345 } |
|
346 |
|
347 } |