dev/provisioning/modules/puppi/manifests/project/svn.pp
changeset 28 b0b56e0f8c7f
equal deleted inserted replaced
27:a2342f26c9de 28:b0b56e0f8c7f
       
     1 # == Define puppi::project::svn
       
     2 #
       
     3 # This is a shortcut define to build a puppi project for the deploy of
       
     4 # file from a svn repo.
       
     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 svn repo to retrieve.
       
    15 #   Format should be in svn friendly standard (http:// svn:// ..).
       
    16 #
       
    17 # [*svn_user*]
       
    18 #   Name of the user to access a private svn repo. Optional.
       
    19 #
       
    20 # [*svn_password*]
       
    21 #   Name of the password to access a private svn repo. Optional.
       
    22 #
       
    23 # [*deploy_root*]
       
    24 #   The destination directory where the retrieved file(s) are deployed.
       
    25 #
       
    26 # [*install_svn*]
       
    27 #   If the svn package has to be installed. Default true.
       
    28 #   Set to false if you install svn via other modules and have resource
       
    29 #   conflicts.
       
    30 #
       
    31 # [*svn_subdir*]
       
    32 #   (Optional) - If you want to copy to the deploy_root only a subdir
       
    33 #   of the specified svn repo, specify here the path of the directory
       
    34 #   relative to the repo root. Default undefined
       
    35 #
       
    36 # [*svn_export*]
       
    37 #   (Optional) - If to use a svn export command instead of checkout
       
    38 #   Default: false (A checkout is done)
       
    39 #
       
    40 # [*tag*]
       
    41 #   (Optional) - A specific tag you may want to deploy. Default undefined
       
    42 #   You can override the default value via command-line with:
       
    43 #   puppi deploy myapp -o "tag=release"
       
    44 #
       
    45 # [*branch*]
       
    46 #   (Optional) - A specific branch you may want to deploy. Default: master
       
    47 #   You can override the default value via command-line with:
       
    48 #   puppi deploy myapp -o "branch=devel"
       
    49 #
       
    50 # [*commit*]
       
    51 #   (Optional) - A specific commit you may want to use. Default undefined
       
    52 #   You can override the default value via command-line with:
       
    53 #   puppi deploy myapp -o "commit=1061cb731bc75a1188b58b889b74ce1505ccb412"
       
    54 #
       
    55 # [*keep_svndata*]
       
    56 #   (Optional) - Define if you want to keep svn metadata directory (.svn)
       
    57 #   in the deploy root. According to this value backup and rollback
       
    58 #   operations change (with keep_svndata set to true no real backups are done
       
    59 #   and operations are made on the svn tree, if set to false, file are copied
       
    60 #   and the $backup_* options used. Default is true
       
    61 #
       
    62 # [*verbose*]
       
    63 #   (Optional) - If you want to see verbose svn utput (file names) during
       
    64 #   the deploy. Default is true.
       
    65 #
       
    66 # [*user*]
       
    67 #   (Optional) - The user to be used for deploy operations.
       
    68 #   If different from root (default) it must have write permissions on
       
    69 #   the $deploy_root dir.
       
    70 #
       
    71 # [*predeploy_customcommand*]
       
    72 #   (Optional) -  Full path with arguments of an eventual custom command to
       
    73 #   execute before the deploy. The command is executed as $predeploy_user.
       
    74 #
       
    75 # [*predeploy_user*]
       
    76 #   (Optional) - The user to be used to execute the $predeploy_customcommand.
       
    77 #   By default is the same of $user.
       
    78 #
       
    79 # [*predeploy_priority*]
       
    80 #   (Optional) - The priority (execution sequence number) that defines when,
       
    81 #   during the deploy procedure, the $predeploy_customcommand is executed
       
    82 #   Default: 39 (immediately before the copy of files on the deploy root).
       
    83 #
       
    84 # [*postdeploy_customcommand*]
       
    85 #   (Optional) -  Full path with arguments of an eventual custom command to
       
    86 #   execute after the deploy. The command is executed as $postdeploy_user.
       
    87 #
       
    88 # [*postdeploy_user*]
       
    89 #   (Optional) - The user to be used to execute the $postdeploy_customcommand.
       
    90 #   By default is the same of $user.
       
    91 #
       
    92 # [*postdeploy_priority*]
       
    93 #   (Optional) - The priority (execution sequence number) that defines when,
       
    94 #   during the deploy procedure, the $postdeploy_customcommand is executed
       
    95 #   Default: 41 (immediately after the copy of files on the deploy root).
       
    96 #
       
    97 # [*disable_services*]
       
    98 #   (Optional) - The names (space separated) of the services you might want to
       
    99 #   stop during deploy. By default is blank. Example: "apache puppet monit".
       
   100 #
       
   101 # [*firewall_src_ip*]
       
   102 #   (Optional) - The IP address of a loadbalancer you might want to block out
       
   103 #   during a deploy.
       
   104 #
       
   105 # [*firewall_dst_port*]
       
   106 #   (Optional) - The local port to block from the loadbalancer during deploy
       
   107 #   (Default all).
       
   108 #
       
   109 # [*firewall_delay*]
       
   110 #   (Optional) - A delay time in seconds to wait after the block of
       
   111 #   $firewall_src_ip. Should be at least as long as the loadbalancer check
       
   112 #   interval for the services stopped during deploy (Default: 1).
       
   113 #
       
   114 # [*report_email*]
       
   115 #   (Optional) - The (space separated) email(s) to notify of deploy/rollback
       
   116 #   operations. If none is specified, no email is sent.
       
   117 #
       
   118 # [*backup_enable*]
       
   119 #   (Optional, default true) - If the backup of files in the deploy dir
       
   120 #   is done (before deploy). If set to false, rollback is disabled.
       
   121 #
       
   122 # [*backup_rsync_options*]
       
   123 #   (Optional) - The extra options to pass to rsync for backup operations. Use
       
   124 #   it, for example, to exclude directories that you don't want to archive.
       
   125 #   IE: "--exclude .snapshot --exclude cache --exclude www/cache".
       
   126 #   This option is used when $keep_svnmeta is set to false
       
   127 #
       
   128 # [*backup_retention*]
       
   129 #   (Optional) - Number of backup archives to keep. (Default 5).
       
   130 #   Lower the default value if your backups are too large and may fill up the
       
   131 #   filesystem.
       
   132 #   This option is used when $keep_svnmeta is set to false
       
   133 #
       
   134 # [*run_checks*]
       
   135 #   (Optional) - If you want to run local puppi checks before and after the
       
   136 #   deploy procedure. Default: "true".
       
   137 #
       
   138 # [*auto_deploy*]
       
   139 #   (Optional) - If you want to automatically run this puppi deploy when
       
   140 #   Puppet runs. Default: 'false'
       
   141 #
       
   142 define puppi::project::svn (
       
   143   $source,
       
   144   $deploy_root,
       
   145   $install_svn              = true,
       
   146   $svn_user                 = 'undefined',
       
   147   $svn_password             = 'undefined',
       
   148   $svn_subdir               = 'undefined',
       
   149   $svn_export               = false,
       
   150   $tag                      = 'undefined',
       
   151   $branch                   = 'master',
       
   152   $commit                   = 'undefined',
       
   153   $keep_svndata             = true,
       
   154   $verbose                  = true,
       
   155   $user                     = 'root',
       
   156   $predeploy_customcommand  = '',
       
   157   $predeploy_user           = '',
       
   158   $predeploy_priority       = '39',
       
   159   $postdeploy_customcommand = '',
       
   160   $postdeploy_user          = '',
       
   161   $postdeploy_priority      = '41',
       
   162   $disable_services         = '',
       
   163   $firewall_src_ip          = '',
       
   164   $firewall_dst_port        = '0',
       
   165   $firewall_delay           = '1',
       
   166   $report_email             = '',
       
   167   $backup_enable            = true,
       
   168   $backup_rsync_options     = '--exclude .snapshot',
       
   169   $backup_retention         = '5',
       
   170   $run_checks               = true,
       
   171   $auto_deploy              = false,
       
   172   $enable                   = true ) {
       
   173 
       
   174   require puppi
       
   175   require puppi::params
       
   176 
       
   177   # Set default values
       
   178   $predeploy_real_user = $predeploy_user ? {
       
   179     ''      => $user,
       
   180     default => $predeploy_user,
       
   181   }
       
   182 
       
   183   $postdeploy_real_user = $postdeploy_user ? {
       
   184     ''      => $user,
       
   185     default => $postdeploy_user,
       
   186   }
       
   187 
       
   188   $bool_install_svn = any2bool($install_svn)
       
   189   $bool_svn_export = any2bool($svn_export)
       
   190   $bool_keep_svndata = any2bool($keep_svndata)
       
   191   $bool_verbose = any2bool($verbose)
       
   192   $bool_backup_enable = any2bool($backup_enable)
       
   193   $bool_run_checks = any2bool($run_checks)
       
   194   $bool_auto_deploy = any2bool($auto_deploy)
       
   195 
       
   196 ### INSTALL GIT
       
   197   if ($bool_install_svn == true) {
       
   198     if ! defined(Package['subversion']) { package { 'subversion': ensure => installed } }
       
   199   }
       
   200 
       
   201 ### CREATE PROJECT
       
   202     puppi::project { $name:
       
   203       enable => $enable ,
       
   204     }
       
   205 
       
   206 
       
   207 ### DEPLOY SEQUENCE
       
   208   if ($bool_run_checks == true) {
       
   209     puppi::deploy { "${name}-Run_PRE-Checks":
       
   210       priority  => '10' ,
       
   211       command   => 'check_project.sh' ,
       
   212       arguments => $name ,
       
   213       user      => 'root' ,
       
   214       project   => $name ,
       
   215       enable    => $enable ,
       
   216     }
       
   217   }
       
   218 
       
   219   if ($firewall_src_ip != '') {
       
   220     puppi::deploy { "${name}-Load_Balancer_Block":
       
   221       priority  => '25' ,
       
   222       command   => 'firewall.sh' ,
       
   223       arguments => "${firewall_src_ip} ${firewall_dst_port} on ${firewall_delay}" ,
       
   224       user      => 'root',
       
   225       project   => $name ,
       
   226       enable    => $enable ,
       
   227     }
       
   228   }
       
   229 
       
   230   if ($bool_keep_svndata == true and $bool_backup_enable == true) {
       
   231     puppi::deploy { "${name}-Backup_existing_data":
       
   232       priority  => '30' ,
       
   233       command   => 'archive.sh' ,
       
   234       arguments => "-b ${deploy_root} -o '${backup_rsync_options}' -n ${backup_retention}" ,
       
   235       user      => 'root' ,
       
   236       project   => $name ,
       
   237       enable    => $enable ,
       
   238     }
       
   239   }
       
   240 
       
   241   if ($disable_services != '') {
       
   242     puppi::deploy { "${name}-Disable_extra_services":
       
   243       priority  => '36' ,
       
   244       command   => 'service.sh' ,
       
   245       arguments => "stop ${disable_services}" ,
       
   246       user      => 'root',
       
   247       project   => $name ,
       
   248       enable    => $enable ,
       
   249     }
       
   250   }
       
   251 
       
   252   if ($predeploy_customcommand != '') {
       
   253     puppi::deploy { "${name}-Run_Custom_PreDeploy_Script":
       
   254       priority  => $predeploy_priority ,
       
   255       command   => 'execute.sh' ,
       
   256       arguments => $predeploy_customcommand ,
       
   257       user      => $predeploy_real_user ,
       
   258       project   => $name ,
       
   259       enable    => $enable ,
       
   260     }
       
   261   }
       
   262 
       
   263     # Here is done the deploy on $deploy_root
       
   264     puppi::deploy { "${name}-Deploy_Files":
       
   265       priority  => '40' ,
       
   266       command   => 'svn.sh' ,
       
   267       arguments => "-a deploy -s ${source} -d ${deploy_root} -u ${user} -gs ${svn_subdir} -su ${svn_user} -sp ${svn_password} -t ${tag} -b ${branch} -c ${commit} -v ${bool_verbose} -k ${bool_keep_svndata} -e ${bool_svn_export}" ,
       
   268       user      => 'root' ,
       
   269       project   => $name ,
       
   270       enable    => $enable ,
       
   271     }
       
   272 
       
   273   if ($postdeploy_customcommand != '') {
       
   274     puppi::deploy { "${name}-Run_Custom_PostDeploy_Script":
       
   275       priority  => $postdeploy_priority ,
       
   276       command   => 'execute.sh' ,
       
   277       arguments => $postdeploy_customcommand ,
       
   278       user      => $postdeploy_real_user ,
       
   279       project   => $name ,
       
   280       enable    => $enable ,
       
   281     }
       
   282   }
       
   283 
       
   284   if ($disable_services != '') {
       
   285     puppi::deploy { "${name}-Enable_extra_services":
       
   286       priority  => '44' ,
       
   287       command   => 'service.sh' ,
       
   288       arguments => "start ${disable_services}" ,
       
   289       user      => 'root',
       
   290       project   => $name ,
       
   291       enable    => $enable ,
       
   292     }
       
   293   }
       
   294 
       
   295   if ($firewall_src_ip != '') {
       
   296     puppi::deploy { "${name}-Load_Balancer_Unblock":
       
   297       priority  => '46' ,
       
   298       command   => 'firewall.sh' ,
       
   299       arguments => "${firewall_src_ip} ${firewall_dst_port} off 0" ,
       
   300       user      => 'root',
       
   301       project   => $name ,
       
   302       enable    => $enable ,
       
   303     }
       
   304   }
       
   305 
       
   306   if ($bool_run_checks == true) {
       
   307     puppi::deploy { "${name}-Run_POST-Checks":
       
   308       priority  => '80' ,
       
   309       command   => 'check_project.sh' ,
       
   310       arguments => $name ,
       
   311       user      => 'root' ,
       
   312       project   => $name ,
       
   313       enable    => $enable ,
       
   314     }
       
   315   }
       
   316 
       
   317 
       
   318 ### ROLLBACK PROCEDURE
       
   319 
       
   320   if ($bool_backup_enable == true) {
       
   321   if ($firewall_src_ip != '') {
       
   322       puppi::rollback { "${name}-Load_Balancer_Block":
       
   323         priority  => '25' ,
       
   324         command   => 'firewall.sh' ,
       
   325         arguments => "${firewall_src_ip} ${firewall_dst_port} on ${firewall_delay}" ,
       
   326         user      => 'root',
       
   327         project   => $name ,
       
   328         enable    => $enable ,
       
   329       }
       
   330     }
       
   331 
       
   332     if ($disable_services != '') {
       
   333       puppi::rollback { "${name}-Disable_extra_services":
       
   334         priority  => '37' ,
       
   335         command   => 'service.sh' ,
       
   336         arguments => "stop ${disable_services}" ,
       
   337         user      => 'root',
       
   338         project   => $name ,
       
   339         enable    => $enable ,
       
   340       }
       
   341     }
       
   342 
       
   343     if ($predeploy_customcommand != '') {
       
   344       puppi::rollback { "${name}-Run_Custom_PreDeploy_Script":
       
   345         priority  => $predeploy_priority ,
       
   346         command   => 'execute.sh' ,
       
   347         arguments => $predeploy_customcommand ,
       
   348         user      => $predeploy_real_user ,
       
   349         project   => $name ,
       
   350         enable    => $enable ,
       
   351       }
       
   352     }
       
   353 
       
   354     if ($bool_keep_svndata == true) {
       
   355       puppi::rollback { "${name}-Recover_Files_To_Deploy":
       
   356         priority  => '40' ,
       
   357         command   => 'archive.sh' ,
       
   358         arguments => "-r ${deploy_root} -o '${backup_rsync_options}'" ,
       
   359         user      => $user ,
       
   360         project   => $name ,
       
   361         enable    => $enable ,
       
   362       }
       
   363     }
       
   364 
       
   365     if ($bool_keep_svndata != true) {
       
   366       puppi::rollback { "${name}-Rollback_Files":
       
   367         priority  => '40' ,
       
   368         command   => 'svn.sh' ,
       
   369         arguments => "-a rollback -s ${source} -d ${deploy_root} -gs ${svn_subdir} -t ${tag} -b ${branch} -c ${commit} -v ${bool_verbose} -k ${bool_keep_svndata}" ,
       
   370         user      => $user ,
       
   371         project   => $name ,
       
   372         enable    => $enable ,
       
   373       }
       
   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 ($disable_services != '') {
       
   388       puppi::rollback { "${name}-Enable_extra_services":
       
   389         priority  => '44' ,
       
   390         command   => 'service.sh' ,
       
   391         arguments => "start ${disable_services}" ,
       
   392         user      => 'root',
       
   393         project   => $name ,
       
   394         enable    => $enable ,
       
   395       }
       
   396     }
       
   397 
       
   398     if ($firewall_src_ip != '') {
       
   399       puppi::rollback { "${name}-Load_Balancer_Unblock":
       
   400         priority  => '46' ,
       
   401         command   => 'firewall.sh' ,
       
   402         arguments => "${firewall_src_ip} ${firewall_dst_port} off 0" ,
       
   403         user      => 'root',
       
   404         project   => $name ,
       
   405         enable    => $enable ,
       
   406       }
       
   407     }
       
   408 
       
   409     if ($bool_run_checks == true) {
       
   410       puppi::rollback { "${name}-Run_POST-Checks":
       
   411         priority  => '80' ,
       
   412         command   => 'check_project.sh' ,
       
   413         arguments => $name ,
       
   414         user      => 'root' ,
       
   415         project   => $name ,
       
   416         enable    => $enable ,
       
   417       }
       
   418     }
       
   419   }
       
   420 
       
   421 ### REPORTING
       
   422 
       
   423   if ($report_email != '') {
       
   424     puppi::report { "${name}-Mail_Notification":
       
   425       priority  => '20' ,
       
   426       command   => 'report_mail.sh' ,
       
   427       arguments => $report_email ,
       
   428       user      => 'root',
       
   429       project   => $name ,
       
   430       enable    => $enable ,
       
   431     }
       
   432   }
       
   433 
       
   434 ### AUTO DEPLOY DURING PUPPET RUN
       
   435   if ($bool_auto_deploy == true) {
       
   436     puppi::run { $name: }
       
   437   }
       
   438 }