-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy.ps1
170 lines (152 loc) · 6.11 KB
/
deploy.ps1
1
2
3
4
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
configuration cts_webservers
{
param(
[Parameter(Mandatory=$true)][ValidateNotNullorEmpty()][String]$NodeName,
[Parameter(Mandatory=$false)][ValidateNotNullorEmpty()]$AllNodesData,
[Parameter(Mandatory=$false)][ValidateNotNullorEmpty()]$AppPoolConfig,
[Parameter(Mandatory=$false)][ValidateNotNullorEmpty()]$Websites,
[Parameter(Mandatory=$false)][ValidateNotNullorEmpty()]$IisConfig
)
# Modules must exist on target pull server
Import-DSCResource -ModuleName xWebAdministration,PSDesiredStateConfiguration
Node "Localhost"
{
#################################################################
# Configure LCM
LocalConfigurationManager
{
ActionAfterReboot = 'ContinueConfiguration'
ConfigurationMode = 'ApplyOnly'
RebootNodeIfNeeded = $true
}
#################################################################
#################################################################
# Enable IIS Central Certificate Store
if ($IISConfig.CcsEnabled -eq $true)
{
cCentralCertificateStore EnableCcs
{
Ensure = "Present"
CertStoreLocation = $IISConfig.CcsPath
Credential = $Credential_iis_cert_store
PrivateKeyPassword = $Credential_iis_ccs_key
}
}
#################################################################
#################################################################
# Enable IIS shared config
if ($IISConfig.SharedConfigEnabled -eq $true)
{
#Enable shared configuration on a unc path
cSharedConfig EnableSharedConfig
{
Ensure = "Present"
Credential = $Credential_svc_deploy_ad
DestinationPath = $IISConfig.SharedConfigPath
}
File DCOMPerm
{
Ensure = "Present"
Credential = $Credential_svc_deploy_ad
SourcePath = $IISconfig.DcomPermLocation
DestinationPath = "%ProgramFiles%\DCOMPerm\DCOMPerm.exe"
}
}
#################################################################
# Create websites
foreach ($Website in $Websites)
{
# Create AppPool
xWebAppPool "AppPool_$($WebName)"
{
Name = "AppPool_" + $Website.Name
Ensure = "Present"
Credential = $Credentials.Value
identityType = "SpecificUser"
startMode = $AppPoolConfig.startMode
rapidFailProtection = $AppPoolConfig.rapidFailProtection
idleTimeout = $AppPoolConfig.idleTimeout
DependsOn = "[File]Folder_$($WebName)"
}
#endregion
$defaultIpAddress = Get-NetIPAddress | Where-Object AddressFamily -EQ IPv4 | Where-Object InterfaceAlias -EQ Ethernet | foreach {$_.IPAddress}
#region Create binding records
# Create normal bindings
$bindings = @()
foreach($binding in $Website.Bindings)
{
switch ($binding.Protocol)
{
# Add http bindings
"http" {
$bindings += MSFT_xWebBindingInformation
{
Protocol = $binding.Protocol
IPAddress = $binding.IPAddress
Port = $binding.Port
HostName = $binding.hostName
}
}
# Add https bindings
"https" {
$bindings += MSFT_xWebBindingInformation
{
Protocol = $binding.Protocol
IPAddress = if ($binding.IPAddress -eq "DefaultIp") {$defaultIpAddress} else {$binding.IPAddress}
Port = $binding.Port
HostName = $binding.hostName
CertificateThumbprint = $binding.CertificateThumbprint
SslFlags = $binding.SslFlags
}
}
}
}#endforeach
# Add all reseller bindings
foreach($reseller in $Website.Resellers.HostHeaders)
{
foreach ($binding in $Website.Resellers.BindingType)
{
switch ($binding.Protocol)
{
# Add http bindings
"http" {
$bindings += MSFT_xWebBindingInformation
{
Protocol = $binding.Protocol
IPAddress = $binding.IPAddress
Port = $binding.Port
HostName = $reseller
}
}
# Add https bindings
"https" {
$bindings += MSFT_xWebBindingInformation
{
Protocol = $binding.Protocol
IPAddress = $binding.IPAddress
Port = $binding.Port
HostName = $reseller
CertificateThumbprint = $binding.CertificateThumbprint
SslFlags = $binding.SslFlags
}
}
}
}
}
#endregion
#region Create the IIS site
xWebsite "Website_$($WebName)"
{
Name = $Website.Name
Ensure = "Present"
State = "Started"
PhysicalPath = $Website.Path
LogPath = $Website.LogPath
ApplicationPool = "AppPool_" + $Website.Name
BindingInfo = $bindings
DependsOn = "[xWebAppPool]AppPool_$($WebName)"
}
#endregion
}#endeach
}
}