In the Finding and installing DSC resources recipe, you discovered and installed some additional DSC resources. The xWebAdministration
module you installed contains a number of DSC resources that enable you to define the configuration of an IIS website.
In this recipe, you are going to make use of this module to create, configure, and view a new website on SRV2
, based on the files created in the Using DSC and built-in resources recipe. This recipe uses the DSC resources contained in the xWebAdministration
module (which you downloaded in the Finding and installing DSC resources recipe).
In this recipe, you use SRV1
to manage DSC resources and configurations, SRV2
as the target node that DSC is going to control, and DC1
as both the DC in the domain and the source of the initial files that make up the application you deploy. You run this recipe on SRV1
.
xWebAdministration
module to SRV2
using the following code:$CIHT = @{ Path = 'C:Program FilesWindowsPowerShell' + 'ModulesxWebAdministration' Destination = '\SRV2C$Program FilesWindowsPowerShell'+ 'Modules' Recurse = $True } Copy-Item @CIHT
SRV2
and local MOF files on SRV1
using the following code:$RIHT =@{ Path = '\SRV2C$WindowsSystem32configuration*.mof' ErrorAction = 'SilentlyContinue' } Get-Childitem @RIHT | Remove-Item @RIHT -Force Remove-Item C:DSC* -Recurse -Force
xWebAdministration
module using the following code:Configuration RKAppSRV2 { Import-DscResource -ModuleName xWebAdministration Import-DscResource -ModuleName PSDesiredStateConfiguration Node SRV2 { Windowsfeature IISSRV2 { Ensure = 'Present' Name = 'Web-Server' } Windowsfeature IISSrvTools { Ensure = 'Present' Name = 'Web-Mgmt-Tools' DependsOn = '[WindowsFeature]IISSRV2' } File RKAppFiles { Ensure = 'Present' Checksum = 'ModifiedDate' Sourcepath = '\DC1ReskitApp' Type = 'Directory' Recurse = $true DestinationPath = 'C:ReskitApp' DependsOn = '[Windowsfeature]IISSRV2' MatchSource = $true } xWebAppPool ReskitAppPool { Name = 'RKAppPool' Ensure = 'Present' State = 'Started' DependsOn = '[File]RKAppFiles' } xWebApplication ReskitAppPool { Website = 'Default Web Site' WebAppPool = 'RKAppPool' Name = 'ReskitApp' PhysicalPath = 'C:ReskitApp' Ensure = 'Present' DependsOn = '[xWebAppPool]ReskitAppPool' } Log Completed { Message = 'Finished Configuring ReskitAp via DSC' } } # End of SRV2 Configuration } # End of Configuration
C:DSC
on SRV1
using the following code:RKAppSRV2 -OutputPath C:DSC
SRV2
using the following code:Start-DscConfiguration -Path C:DSC -Verbose -Wait
Start-Process 'HTTP://SRV2.Reskit.Org/ReskitApp/'
In step 1, you copy the xAdministration
module to SRV2
, then in step 2, you clear out any MOF files on SRV2
and SRV1
. These two steps produce no output.
In step 3, you create a configuration document, RKAppSRV2
. This step also produces no screen output.
In step 4, you create the MOF file for this recipe by executing the RKAppSRV2
function, which should yield the output shown in the following screenshot:
In step 5, you deploy this new configuration to SRV2
using the -Wait
and -Verbose
switches, producing an output like the following:
Finally, in step 6, you view the web pages created by the earlier steps. If you first navigate to the home page of the application, using step 6. You should see the following:
From this page, if you click to page 2, you should see this:
In step 3, you created a configuration block that does the following:
SRV2
with two Windows features (Web-Server
and Web-Mgmt-Tools
)DC1
to SRV2
RKAppPool
ReskitApp
This step also demonstrates the dependency mechanism in DSC. A dependency allows you to state that a particular resource configuration can only be performed after some other resource configuration has completed. For example, this configuration does not create a ReskitApp
application until the RKAppPool
application pool exists and does not do either until the WindowsFeature
resource has finished installing IIS.
This recipe uses the push model for DSC deployment. In this recipe, you manually copy the xWebAdministration
module to SRV2
as part of the recipe. If you use a pull server model to deploy DSC, target nodes can download the necessary resources from the pull server, which greatly simplifies deployment of DSC resources. The two recipes later in this chapter (Implement an SMB pull server and Implement a DSC web pull server) show you how to configure a pull server.
3.22.74.66