Ah! I always struggle to explain these concepts and the superiority of Policy-Driven, but I think I’ve found a good example! My Air Conditioning systems…
Configuration Management
Another common challenge with DSC, is how to compose DSC configurations.
People have seen the trick of having a Configuration, and the following code within:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Configuration MyDSCConfig { | |
Node $ConfigurationData.AllNodes.nodename { | |
if($Node.roles -contains 'MyRole') { | |
# do stuff here, like calling DSC Resources | |
MyCompositeResource StuffForMyRole { | |
# … | |
} | |
} | |
if($Node.roles -contains 'MyOtherRole') { | |
MyOtherResource OtherStuff { | |
# … | |
} | |
} | |
} | |
} |
This is a good way to get started and works well for small-ish configurations, but it gets out of hand pretty quickly, as it’s hard to read all the if
statements and their content. Some variant of this are using Where
clauses around the Node expression.
I’m writing and using a PowerShell module called “Datum” to manage DSC Configuration Data, and raise cattle at work. This is a write up to explain the problem, and why I’m writing it.
I assume you already know a bit about Desired State Configuration, but if it’s new to you or vague, go grab yourself The DSC Book by Don Jones & Missy Januszko, which packs all you need to know about out-of-the-box DSC, and more.
This post tries to explain the DSC Configuration Data composition challenge that I attempt to solve with Datum. It does not include the solution and how to use Datum to solve those problems: you can look on the GitHub repository and see an example of a Control Repository, or come to the PowerShell Summit 2018, where I’ll be presenting Datum used in a DSC Infrastructure.
Here’s a quick function to allow you something close to splatting with DSC resources:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Get-DscSplattedResource { | |
[CmdletBinding()] | |
Param( | |
[String] | |
$ResourceName, | |
[String] | |
$ExecutionName, | |
[hashtable] | |
$Properties | |
) | |
$stringBuilder = [System.Text.StringBuilder]::new() | |
$null = $stringBuilder.AppendLine("Param([hashtable]`$Parameters)") | |
$null = $stringBuilder.AppendLine(" $ResourceName $ExecutionName { ") | |
foreach($PropertyName in $Properties.keys) { | |
$null = $stringBuilder.AppendLine("$PropertyName = `$(`$Parameters['$PropertyName'])") | |
} | |
$null = $stringBuilder.AppendLine("}") | |
Write-Debug ("Generated Resource Block = {0}" -f $stringBuilder.ToString()) | |
[scriptblock]::Create($stringBuilder.ToString()).Invoke($Properties) | |
} | |
Set-Alias –Name x –Value Get-DscSplattedResource |
Here’s why you may need it.
This is the second article in a “getting started with DSC Development”, covering tools and workflow. The previous post was covering general Windows Automation techniques, some of them existing since the Windows XP days and before!
This time we’ll look at tools, techniques and workflow that will enable us to make changes using scientific method, iteratively.
This is the first article in a series that aim to explore one way of getting started with DSC Development, covering tools and workflow.
In very short and abstract, the life cycle of a Windows Server could look like:
- Deployment (aka OSD)
- Configuration
- Maintenance
- Decommission
This series aims to focus at the Configuration part, mainly in its development phase, but also covers the basics of creating windows Image for experimentation purposes. The idea is to get started experimenting quickly, but I would not use this approach of Image creation for something that needs to be maintained.
I wanted write down somewhere what technical books I’ve read, or I want to read in future.
Here’s my list, please comment to suggest some more! A couple of them haven’t been released yet, but I want to grab them either when they’re released, or through MEAP.
- The Phoenix Project, Gene Kim, Kevin Behr, George Spafford.
- The Goal: A Process of Ongoing Improvement, Eliyahu M. Goldratt, Jeff Cox
- Threat Modeling: Designing for Security, Adam Shostack
- The Lean Startup: How constant innovation creates radically successful Businesses, Eric Ries
- Visible Ops Hanbook: Implementing ITIL in 4 Practical and Auditable Steps, Gene Kim, George Spafford
- Visible Ops Private Cloud: From Virtualization to Private Cloud in 4 Practical Steps, Jeanne Morain, Kurt Milne
- Visible Ops Security: Achieving common security and IT Operations Objectives in 4 Practical Steps, Gene Kim, Paul Love
- Clean Code: A Handbook of Agile Software Craftmanship, Robert C. Martin
- Learn PowerShell in a month of Lunches, Don Jones, Jeffery Hicks
- Learn PowerShell Toolmaking in a month of Lunches, Don Jones, Jeffery Hicks
- Learn SQL SERVER Administration in a month of Lunches, Don Jones
- Learn Windows IIS in a month of Lunches, Jason Helmick
- Learn Active Directory Management in a Month of Lunches, Richard Siddaway
- Learn ConfigMgr 2012 in a Month of Lunches, James Bannan
- Learn Git in a Month of Lunches, Rick Umali
- PowerShell Deep Dives, Edited by Jeffery Hicks, Richard Siddaway, Oisin Grehan, Aleksandar Nikolic, contributed by many 🙂
- Windows PowerShell Cookbook, Lee Holmes
- Continuous Delivery: Reliable Software Releases Through Build, Test, and Deployment Automation, Jez Humble, David Farley
- The 7 Habits of Highly Effective People, Stephen R. Covey
- PRINCE2 for Dummies, Nick Graham
- ITIL for Dummies, Peter Farenden
- Contractors’ Handbook: The Expert guide for UK contractors and Freelancers, Dave Chaplin
Adding a few suggested by BenH following DSCCamp:
- Lean from the Trenches: Managing Large-Scale Projects with Kanban, Henrik Kniberg
- Kanban, David J. Anderson
- Design Patterns: Element of Reusable Object-Oriented Software, Erich Gamma, Richard Helm, Ralph Johnson, John Vlissides
That’s all I have in mind at the moment, but my books are all stacked in a corner of the leaving room, waiting for the bookshelf to be built…
What do you think, anything worth adding?