DevOps – Desired State Configuration – Mohit K. Gupta DevOps – Desired State Configuration –
SQL Summit Annual International Conference November 6 -9 | Seattle, WA 2 Days of Pre-Cons 200+ sessions over 3 days Over 5,000 SQL Professionals Evening Networking Activities
Please Support Our Sponsors
Let’s Not Distract Others Please silent your phone We can chat later Please don’t snore
Agenda Introduction to Desired State Configuration (DSC) Requirements DSC v4 and DSC v5 DSC Terminology Development & Deployment DSC Resources
Introduction
Introduction DSC is a configuration management platform Service and Application Agnostic Standards-based Distributed Benefits Ensures configuration Supports continuous deployment Prevents configuration drift Change control becomes a text file
Challenge 1: Deployment & Consistency Manual deployment is neither repeatable nor consistent Dev, Test, Prod do not match Build scripts can break mid-stream
Challenge 2: Server Outage Change happened somewhere Configuration drift
Imperative vs Declarative Language Add-WindowsFeature Windows-Server-Backup Declarative Configuration BaseBuild { WindowsFeature Backup { Ensure = "Present" Name = "Windows-Server-Backup" }
Requirements
Operating System Requirements WMF 4.0 WMF 5.0 Windows 7 Upgrade Windows 2008 R2 Windows 8 Windows 2012 Windows 8.1 Default Windows 2012 R2 Windows 10 Windows 2016 PowerShell DSC requires .NET Framework 4.5
Windows 2008 R2 Compatibility Supports PowerShell DSC via WMF 4.0 or WMF 5.0 update Built-in resources will work Limited support for community resources
DSC v4 and DSC v5
DSC Command-Lets by Version Name DSC v4 DSC v5 Configuration X Get-DscConfiguration Get-DscLocalConfigurationManager Get-DscResource New-DscCheckSum Restore-DscConfiguration Test-DscConfiguration Set-DscLocalConfigurationManager Start-DscConfiguration Remove-DscConfigurationDocument Stop-DscConfiguration Update-DscConfiguration Find-DscResource Get-DscConfigurationStatus Invoke-DscResource Publish-DscConfiguration Enable-DscDebug Disable-DscDebug
Demonstration - Deploy SQL Server -
DSC Terminology
Terminology Configuration File Built-In Resources MOF Local Configuration Manager Push / Pull
Configuration File Configuration IISWebsite { Node Server1 WindowsFeature IIS Ensure = "Present" Name = "Web-Server" } WindowsFeature ASP Name = "Web-Asp-Net45"
Built-In Resources File Archive Environment Group Log Package Registry Script Service User WindowsFeature WindowsProcess
MOF File MOF – Managed Object Format Industry standard text file contain resource and configuration data. Consumed by WMI/CIM. localhost.mof
Local Configuration Manager (LCM) The “DSC engine” Enforces configuration and consistency Can auto-correct a state that changes Settings to configure intervals, reboots, etc. Local Configuration Manager
LCM Properties Get-DscLocalConfigurationManager ConfigurationMode ApplyOnly ApplyAndMonitor (Default) ApplyAndAutoCorrect ConfigurationModeFrequencyMins Interval to apply configuration RefreshFrequencyMins Interval to pull configuration RefreshMode Push Pull Disabled
Push / Pull Authoring Staging Nodes Config Pulled IIS Config Pulled Server1 Config Pushed Config Pulled Server1.mof Server1 Configs Deployed Server1.mof Config Pulled IIS Server1.mof Server1 Configs Deployed Server1.mof File Share
LCM Example - Pull [DscLocalConfigurationManager()] Configuration LCMPull { Node localhost Settings ActionAfterReboot = 'ContinueConfiguration' AllowModuleOverWrite = $True ConfigurationID = 'a019aeb4-27e0-4ae2-b2f9-edc0fc620338' ConfigurationMode = 'ApplyAndAutoCorrect' ConfigurationModeFrequencyMins = 15 RefreshFrequencyMins = 30 StatusRetentionTimeInDays = 7 RebootNodeIfNeeded = $True RefreshMode = 'Pull' } ConfigurationRepositoryWeb PullServer ServerURL = "https://psv52012r2pull.contoso.com:8080/PSDSCPullServer.svc" AllowUnsecureConnection = $false
LCM Example - Push [DscLocalConfigurationManager()] Configuration LCMPushv5 { Node localhost Settings ActionAfterReboot = 'ContinueConfiguration' AllowModuleOverWrite = $True ConfigurationMode = 'ApplyAndAutoCorrect' ConfigurationModeFrequencyMins = 15 RefreshFrequencyMins = 30 StatusRetentionTimeInDays = 7 RebootNodeIfNeeded = $True RefreshMode = 'Push' } LCMPushv5 Set-DSCLocalConfigurationManager -Path .\LCMPushv5
Development & Deployment
Quick Configuration – Snippets & Syntax CTRL + J snippet for configuration. Get-DscResourceName -Syntax Copy and Paste
Quick Configuration - IntelliSense Type the resource name and curly braces. CTRL+SPACE for IntelliSense. Use TAB completion for enumerated property values and DependsOn.
Quick Configuration - DependsOn Configuration DependsOnExample { Import-DscResource -ModuleName PSDesiredStateConfiguration Node localhost { File DSCTempFolder { DestinationPath = 'C:\DSCTemp\' Ensure = 'Present' Type = 'Directory' } Archive ExtractZIP { Path = 'C:\InstallSource\LogParser.zip' Destination = 'C:\DSCTemp\logparser\' Force = $true DependsOn = '[File]DSCTempFolder' Package InstallLogParser { Ensure = 'Absent' Name = 'Log Parser 2.2' Path = 'C:\DSCTemp\logparser\logparser.msi' ProductId = '4AC23178-EEBC-4BAF-8CC0-AB15C8897AC9' DependsOn = '[Archive]ExtractZIP' The order of execution of resources is not guaranteed. Use the common property DependsOn to establish order in the format [Resource]Name.
Start-DscConfiguration C:\Windows\System32\Configuration\ Start-DscConfiguration publishes and applies pending.mof 2. Renames current to previous previous.mof current.mof pending.mof 3. Renames pending to current
Start-DscConfiguration -UseExisting 1. Reapplies current.mof previous.mof current.mof
Restore-DscConfiguration previous.mof current.mof pending.mof 1. PUSH mode only. Renames previous to pending
Remove-DscConfigurationDocument Remove-DscConfigurationDocument -Stage Current Pending Previous previous.mof current.mof pending.mof Used to “unconfigure” DSC configuration, leaving the settings applied.
Query the Desired State Test-DscConfiguration – true/false desired state Get-DscConfiguration – current state of configured resources Get-DscConfigurationStatus – Date & time, success or failure Get-DscConfigurationStatus -All – History of DSC events and status
DSC Resources
Resources A resource is PowerShell code that tells a node how to configure the settings Use property values as parameters Can express dependencies Deployed using PowerShell modules
Resource Types Built-In Resource Kit(s) Community (ex. TechNet Script Center, GitHub) Custom
Key Command Lets Command Let Description Get-DscResource Shows current installed resources on system. Can also be used to determine the resource syntax. Find-DscResource Find-Module Search for repositories online. Install-Module Save-Module Install the DSC Resource.
Resource Naming Conventions Resource Name Meaning [ ]FileSystem This resource or other like it are built-in resources with no-prefix. [x]SQLServer Microsoft DSE Resource Kit, stands for eXperimental. Developed by Microsoft. [c]ResourceName Community Developed.
Questions?