-
Notifications
You must be signed in to change notification settings - Fork 3
/
PetShopWebApp_Config.psm1
155 lines (139 loc) · 5.34 KB
/
PetShopWebApp_Config.psm1
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
Configuration PetShopWebApp
{
Import-DSCResource -Module xWebAdministration
Import-DSCResource -Module xWebDeploy
Import-DSCResource -Module xSqlPs
Import-DSCResource -Module xNetworking
Import-DscResource -module xFileContent
Import-DscResource -module xPSDesiredStateConfiguration
#Configure SQL backend
Node $Allnodes.Where{$_.Role -contains "MSSQL"}.Nodename
{
$CacheScriptContent = {$appcmd = "$env:SystemDrive\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_regsql.exe"; `
& $appcmd -S .\ -U OaaS -P pass@word1 -A all -d MSPetShop4Services; `
& $appcmd -S .\ -U OaaS -P pass@word1 -d MSPetShop4 -ed; `
& $appcmd -S .\ -U OaaS -P pass@word1 -d MSPetShop4 -t Item -et; `
& $appcmd -S .\ -U OaaS -P pass@word1 -d MSPetShop4 -t Product -et; `
& $appcmd -S .\ -U OaaS -P pass@word1 -d MSPetShop4 -t Category -et; `
echo "Database Caching successfully enabled. Database=MSPetShop4" >> $env:ALLUSERSPROFILE\CacheScript.txt
}
#Enable Remove Access to SQL Engine and SQL browser
xFireWall RemoteAccessOnSQLEngine
{
Name = "SqlServer"
Ensure = "Present"
Access = "Allow"
State = "Enabled"
ApplicationPath = "c:\Program Files\Microsoft SQL Server\MSSQL12.MSSQLSERVER\MSSQL\Binn\sqlservr.exe"
Profile = "Private"
}
# Provisioning databases with some pet information
xRemoteFile PetshopSampleDataScript
{
Uri = $Node.SampleScriptURI
DestinationPath = "c:\programdata\SampleData.sql"
}
xOSql PetShopSampleData
{
SQLServer = $Node.SQLServerName
SqlUserName = (Import-Clixml .\SQLAdmin.xml).UserName
SqlPassword = (Import-Clixml .\SQLAdmin.xml).GetNetworkCredential().password
SQLFilePath = "c:\programdata\SampleData.sql"
}
#Enables sql database caching
Script PetShopSQLCacheDependency
{
SetScript = $CacheScriptContent
GetScript = {@{}} #no easy way to get the sql database cache flag
TestScript = {if(Test-path c:\programdata\CacheScript.txt){if((get-content c:\programdata\CacheScript.txt) -match "Username=OaaS, Password=pass@word1, Database=MSPetShop4"){return $true}else{return $false}}else{return $false}}
}
}
#Configure IIS front end
Node $Allnodes.Where{$_.Role -contains "Web"}.Nodename
{
# Install IIS and Web Management Tools
WindowsFeature WebServer
{
Name = "Web-server"
Ensure = "Present"
}
WindowsFeature WebAppDev
{
Name = "Web-Asp-Net45"
Ensure = "Present"
}
WindowsFeature IISManagementTools
{
Name = "Web-Mgmt-Tools"
Ensure = "Present"
}
xWebsite Default
{
Ensure = "Present"
Name = "Default Web Site"
PhysicalPath = "%SystemDrive%\inetpub\wwwroot"
State = "Started"
BindingInfo = MSFT_xWebBindingInformation
{
Protocol = "HTTP"
Port = "8080"
}
}
File WebsiteDirectory
{
Ensure ="Present"
Type = "Directory"
DestinationPath = "c:\inetpub\MSPetShop"
}
# IIS server prep. Enabling site remote access
xWebSite Petshop
{
Ensure = "Present"
Name = "MSPetShop"
PhysicalPath = "c:\inetpub\MSPetShop"
State = "Started"
BindingInfo = MSFT_xWebBindingInformation
{
Protocol = "HTTP"
Port = "80"
}
}
xFireWall EnableRemoteIISAccess
{
Name = "PetShop_IIS_Port"
Ensure = "Present"
Access = "Allow"
State = "Enabled"
Protocol = "TCP"
Direction = "Inbound"
LocalPort = "80"
Profile = "Any"
}
#Deploys PetShop Web Server in IIS
Package WebDeployTool
{
Ensure = "Present"
Path = $Node.WebDeployURI
ProductId = "{1A81DA24-AF0B-4406-970E-54400D6EC118}"
Name = "Microsoft Web Deploy 3.5"
Arguments = "/quiet"
}
xRemoteFile PetshopSource
{
Uri = $Node.WebPackageURI
DestinationPath = "c:\data\petshop.zip"
}
xWebPackageDeploy WebPackage
{
Ensure = "Present"
SourcePath = "c:\data\petshop.zip"
Destination = "MSPetShop"
}
xFindAndReplace Web2Config
{
FilePath = "C:\inetpub\MSPetShop\web.config"
Pattern = "server=.\\TestDSC;"
ReplacementString = "server=$($Node.SQLServerName)\;"
}
}
}