DSC is management platform, used to manage your IT infrastructure, presenting configuration as code.
So this code is just powershell script which contains Windows features or roles needs to be maintained with comply of your organisation. Code would be pushed to the Nodes where this code need to maintain Configuration settings.
DSC not only maintains the configuration of the nodes but also monitor and can provide alerts is a node is not compliant.
lthough DSC was introduced in Windows Server 2012 R2, it is available for down-level operating systems via the Windows Management Framework (WMF) package.
Some of the benefits of Desired State Configuration:
* To automate the configuration tasks for one or more nodes
* To standardize the nodes with same set of configuration
* Faster deployments and reliable
* Monitor the compliance state of nodes and can automatically fix it(Make it compliant)
There are two types of architecture with DSC:
Push mode: the configurations are sent (“pushed”) manually towards one or more units that we call “node”. This action is done by an administrator.
Pull mode: a “pull server” is created and the nodes contact this server at regular intervals so as to obtain their configuration.
There are 3 components of Desired State Configuration in Powershell:
1. Local Configuration Manager - Engine which facilitates the Pull and Push mode of the system. It control flow implemented by resources to ensure that the state defined in configuration is maintained.
2. Configuration Files - Declarative powershell scripts which can be applied repeatedly and will always give the same result and it won’t generate errors if the configuration was already applied.
3. Resources - contain the code that put and keep the target of a configuration in the specified state. Resources reside in PowerShell modules and can be written to model something as generic as a file or a Windows process, or as specific as an IIS server or a VM running in Azure.
Lets Make a Small DSC example:
Two Files need to be created -
1. Default.html
2. CreateWebsite.ps1
Scenario - We need to install WebServer Role in node with default page.
Paste Below in Default.html
<head>Test Page</head>
<body>
<p>Sample for Desired state configuration in Powershell</p>
</body>
Paste Below in CreateWebsite.ps1
Configuration CreateWebsite {
Import-DscResource -ModuleName PsDesiredStateConfiguration
Node 'VMSRV1' {
WindowsFeature WebServer {
Ensure = "Present"
Name = "Web-Server"
}
File WebsiteContent {
Ensure = 'Present'
SourcePath = 'c:\temp\Default.html'
DestinationPath = 'c:\inetpub\wwwroot'
}
}
}
Steps to Run:
1. First you need to compile the CreateWebsite.ps1 file, You can verify the output by going to Present Directory where script is running and check if MOF(Managed Object Format) file is create with name "VMSVR1".
2. To Apply the configuration which we created, use command "Start-DscConfiguration ./CreateWebsite.ps1"
3. It will show some output, after execution is completed. Please check if IIS role has been installed and you can see default website with Default.html which we created.
So this code is just powershell script which contains Windows features or roles needs to be maintained with comply of your organisation. Code would be pushed to the Nodes where this code need to maintain Configuration settings.
DSC not only maintains the configuration of the nodes but also monitor and can provide alerts is a node is not compliant.
lthough DSC was introduced in Windows Server 2012 R2, it is available for down-level operating systems via the Windows Management Framework (WMF) package.
Some of the benefits of Desired State Configuration:
* To automate the configuration tasks for one or more nodes
* To standardize the nodes with same set of configuration
* Faster deployments and reliable
* Monitor the compliance state of nodes and can automatically fix it(Make it compliant)
There are two types of architecture with DSC:
Push mode: the configurations are sent (“pushed”) manually towards one or more units that we call “node”. This action is done by an administrator.
Pull mode: a “pull server” is created and the nodes contact this server at regular intervals so as to obtain their configuration.
There are 3 components of Desired State Configuration in Powershell:
1. Local Configuration Manager - Engine which facilitates the Pull and Push mode of the system. It control flow implemented by resources to ensure that the state defined in configuration is maintained.
2. Configuration Files - Declarative powershell scripts which can be applied repeatedly and will always give the same result and it won’t generate errors if the configuration was already applied.
3. Resources - contain the code that put and keep the target of a configuration in the specified state. Resources reside in PowerShell modules and can be written to model something as generic as a file or a Windows process, or as specific as an IIS server or a VM running in Azure.
Lets Make a Small DSC example:
Two Files need to be created -
1. Default.html
2. CreateWebsite.ps1
Scenario - We need to install WebServer Role in node with default page.
Paste Below in Default.html
<head>Test Page</head>
<body>
<p>Sample for Desired state configuration in Powershell</p>
</body>
Paste Below in CreateWebsite.ps1
Configuration CreateWebsite {
Import-DscResource -ModuleName PsDesiredStateConfiguration
Node 'VMSRV1' {
WindowsFeature WebServer {
Ensure = "Present"
Name = "Web-Server"
}
File WebsiteContent {
Ensure = 'Present'
SourcePath = 'c:\temp\Default.html'
DestinationPath = 'c:\inetpub\wwwroot'
}
}
}
Steps to Run:
1. First you need to compile the CreateWebsite.ps1 file, You can verify the output by going to Present Directory where script is running and check if MOF(Managed Object Format) file is create with name "VMSVR1".
2. To Apply the configuration which we created, use command "Start-DscConfiguration ./CreateWebsite.ps1"
3. It will show some output, after execution is completed. Please check if IIS role has been installed and you can see default website with Default.html which we created.
No comments:
Post a Comment