Desired state-configuration-ravikanth-august-2013-vtc india

Post on 24-May-2015

1.166 views 0 download

Tags:

Transcript of Desired state-configuration-ravikanth-august-2013-vtc india

Desired State Configuration in PowerShell 4.0

Ravikanth Chaganti@Ravikanth

http://www.ravichaganti.com/blog

About Me

• Work at Dell Inc.• Windows PowerShell MVP since 2010• Founder and Editor of PowerShell

Magazine• Twitter: @Ravikanth• Facebook: /Ravikanthc• http://www.powershellmagazine.com• http://www.ravichaganti.com/blog

Desired State Configuration

• A new management platform for management of configuration data– Helps prevent configuration drift– Helps DevOps!

• Provides– Language Extensions– Cmdlets to manage configuration– Built-in resources

DSC Basics … Configuration ArchiveDemo { Node SRV3-WS2012R2 { Archive ArchiveDemo { Path = "\\10.10.10.101\Backup\Scripts.zip" DestinationPath = "C:\Scripts" Ensure="Present" } }}

ArchiveDemo

Declarative Syntax

.PS1

• Can take parameters like a function

• Uses PowerShell Remoting

• Each Configuration document gets converted to a MOF

DSC Resources

ArchiveEnvironmen

tFile Group

Log Package Process Registry

Role Script Service User

… Of course, You can build your own resources

BUILT-IN RESOURCESDemo

Custom DSC Resources

• Create a MOF file describing the resource• Create a PowerShell Module (PSM1 &

PSD1)– Set-TargetResource– Test-TargetResource– Get-TargetResource–Must be idempotent

• Copy all files to C:\Windows\system32\WindowsPowerShell\v1.0\Modules\PSDesiredStateConfiguration\PSProviders

Custom Resource - MOF[version("1.0.0"), FriendlyName("HostsFile")] class HostsFile : MSFT_BaseResourceConfiguration{ [Key] string hostName; [Key] string ipAddress; [write,ValueMap{"Present", "Absent"},Values{"Present", "Absent"}] string Ensure;};

• [Key] for unique attributes; become mandatory

• [Write] for attributes for which a value can be specified

• [Read] for readonly attributes

• ValueMap defines the possible values

• Naming: classname.schema.mof

HostsFile.Schema.Mof

Custom Resource – Module

• Same parameters on – Get-TargetResource• Must return hashtable of the configuration

– Set-TargetResource– Test-TargetResource• Must return true or false

• Module Manifest is required– Use New-ModuleManifest

DSC Execution Flow

Start

Run Test-

TargetResource

Run Set-

TargetResource

False

End

True

CUSTOM DSC RESOURCEDemo

DSC Configuration Data

• Separate business logic from configuration data

• Makes configuration logic more re-usable

$AllNodes = @( @{ NodeName = "*"; RecurseValue =

$true }, @{ NodeName = “SRV2"; HostName = "Web01"; IPAddress = “10.10.10.101"; },

@{ NodeName = “SRV3"; HostName = "Web02"; IPAddress = “10.10.10.102"; },);

DSC – Local Configuration Manager

• Each computer with PS 4.0 runs a DSC Engine (as SYSTEM)

• Responsible for calling the DSC resources

• LCM properties can be updated to use pull model; of course, using DSC

CONFIGURING CM Demo

Configuration Delivery

• Push– Default delivery mechanism– Start-DSCConfiguration

• Pull– DSC Service– IIS Endpoint– Requires • Windows Server 2102 or• Windows Server 2012 R2

Summary

• Understanding DSC and implementing custom resources can change the way configuration management is done

• Endless opportunities for System administrators and DevOps engineers

Resources

• DSC Overviewhttp://technet.microsoft.com/en-us/library/dn249912.aspx

• DevOps and DSCwww.youtube.com/watch?v=w3A2RmppBG4

• DSC at TechEd 2013http://channel9.msdn.com/Events/TechEd/NorthAmerica/2013/MDC-B302

• Github repo for DSC custom resourceshttps://github.com/smurawski/DSC-Contrib

QUESTIONS?