Puppet Class: mssql::server::update

Defined in:
manifests/server/update.pp

Summary

Apply SQL Server cumulative patch

Overview

Examples:

include mssql::server::update

Parameters:

  • logoutput (Boolean) (defaults to: true)
  • ensure (Enum['present','absent']) (defaults to: lookup('mssql.server.ensure'))


5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'manifests/server/update.pp', line 5

class mssql::server::update (
  Boolean $logoutput = true,
  Enum['present','absent'] $ensure = lookup('mssql.server.ensure'),
) {

  notify { 'Processing mssql::server::update' : }

  if ($facts['operatingsystem'] == 'windows') {

    $source = lookup({
      'name'          => 'mssql.server.source.update',
      'default_value' => undef,
    })

    if (!empty($source) and ($ensure == 'present'))  {

      $instancename = lookup({
        'name'          => 'mssql.server.instance.instancename',
        'default_value' => 'MSSQLSERVER',
      })

      exec { 'Apply SQL Server Cumulative Update' :
        command   => Sensitive(@("EOT")),
          Try {
            Set-Location "${regsubst($source ,'/', '\\\\', 'G')}"
            Start-Process `
              -FilePath "${regsubst($source ,'/', '\\\\', 'G')}\\setup.exe" `
              -ArgumentList "/q /IAcceptSQLServerLicenseTerms /Action=Patch /AllInstances" `
              -Wait `
              -NoNewWindow `
              -RedirectStandardOutput ${regsubst("\'${::env_temp}/sqlserverpatch.log\'", '(/|\\\\)', '\\', 'G')}

            Start-Sleep -Seconds 10

            If (
              (Get-Content ${regsubst("\'${::env_temp}/sqlserverpatch.log\'", '(/|\\\\)', '\\', 'G')} -ErrorAction Stop) -notlike "*Error*"
            ) {
              Exit 0
            } Else {
              Exit 1
            }
          } Catch {
            Exit 1
          }
          |-EOT
        provider  => powershell,
        logoutput => $logoutput,
        onlyif    => Sensitive(@("EOT")),
          If (
            (Get-ItemProperty `
              -Path 'HKLM:/SOFTWARE/Microsoft/Microsoft SQL Server/Instance Names/SQL' `
              -ErrorAction SilentlyContinue `
            ).${instancename}) {
            0
          } Else {
            Throw 'Instance ${instancename} is not present.'
          }
          If (Test-Path -Path "${regsubst($source ,'/', '\\\\', 'G')}\\setup.exe") {
            0
          } Else {
            Throw 'Path for ${source} is invalid.'
          }
          |-EOT
      }
    }
  } else {
    fail("Unsupported Platform - ${$facts['operatingsystem']}")
  }
}