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