Day 35: Automating the Steps of PowerShell DSC MOF and Node Configuration

 

Welcome to Day 35 of the “100 Days of DevOps with PowerShell”! For background on our goals in this series, see Announcing the “100 Days of Devops with PowerShell” Series here at SCC. If this is the first time you are viewing an article of the series and you are new to DevOps and PowerShell DSC, I encourage you to read through the previous installments, particularly Day 1.

Objective of this post…

Let’s talk for a moment about the objectives for this post, which is really a reminder of what we are trying to bring to the community with “100 Days of DevOps” services as a whole.

PowerShell DSC is a great new tool to deliver on the promise of DevOps. However, many of the examples you will find on the Internet today still involve some manual effort, and simplified approaches rather than optimized approaches…and that’s okay. The knowledge base has to begin with the foundational components. The point of this series is to build on that existing work and our own installments to incrementally advance the dialogue around PowerShell DSC from simple examples to optimized and varied enterprise use cases. In this post, we’re going to take another incremental step. I want to bring the steps for automated bulk configuration into focus.

In my installment last week, “Day 30: Enabling Highly Standardized Web Farm Configuration with PowerShell DSC (Part 2)”, I extended a previous post to automate configuration of multiple servers at once. There were still a few things not completely automated, and I want to build a couple of functions that will ultimately lead us to a seamless end-to-end PowerShell DSC configuration process.

image

In this post, I will focus on the three items highlighted in the diagram above, turning the following code snippets into functions:

  • Rename Configuration MOFs, Copy to Pull Server and Create Checksum (Step 3d in Day 30)
  • Updating DSC Configuration on Managed Nodes (Step 4 in Day 30)

Small changes, but part of that incremental process of building an optimized end-to-end bulk configuration process that is enterprise-ready.

Item #1: Rename Configuration MOFs, Copy to Pull Server and Create Checksum

After you create the Configuration MOF for a node, you then have to do a few things to get it ready to be pulled down by the managed node.

This PowerShell function, which is an extended version of the script in Step 3d in Day 30, performs the followings steps:

  • Locates the MOF file for the the specified node (managed server, server2.contoso.com in this example) just created (Step 3c in Day 30)
  • Copies the file to the specified directory on the DSC Pull Server (Don’t have a DSC Pull Server .yet? STOP, check out Day 1 and Day 6 and get it done)
  • Names the file in the target directory with the guid of the node (from server2.contoso.com.mof to 79ad26df-4f09-4526-82e1-a849bcb123ae.mof in this case).

The parameters of the function are as follows:

  • $PullServer – Name of your DSC Pull Server
  • $NodeFQDN – Name of the managed node
  • $Guid – The guid of the managed node. If the node is already managed, remember you don’t need to create a new guid,
  • $SourcePath – The path to the MOF file you have already created (see Steps 3a and 3b in Day 30)

Here’s the function. on line 18, you will see how to call the function in your scripts.

 

NOTE: On line 18, you will notice I called the DSC Pull Server by locally host, indicating I ran this script on the pull server. You could call the Pull Server by name and run this from your workstation with the Desired State Configuration (DSC-Service) installed.

The result is the Configuration MOF file (and the required checksum) in the place for the managed node to pick up the file next time it checks in, assuming it is already configured in DSC pull mode.

image

IMPORTANT: Remember, for nodes already under management, you simply need to look up the nodes guid in the central repository you are storing them (see Day 5 and Day 16).

Let’s step through the next script, extended to create a function for configuring nodes for pull mode in bulk.

Item #2: Updating Node Configuration

This is the snippet we have used several times in this series to update the configuration of our managed nodes. Only a couple of tiny changes here make a big difference. First, parameterizing the server name in line 5 so we can use this function to configure nodes for pull mode in bulk. Parameterizing the node name means we can call the function repeatedly as we automate bulk configuration. You will also notice I am calling the node by name rather than localhost (as you see in many examples), enabling configuration of all my managed servers from a central management workstation rather than running locally on the node. Remember to change the http to https in the sample below if you configured an SSL-enabled DSC Pull Server (explained in Day 6).

 

While this script will work for nodes for which you want to update the configuration or configure for the first time, it is assumed you have already installed the Desired State Configuration (DSC-Service) feature on the target node.

Conclusion

That’s all for this installment, bringing us a bit closer to the optimal state. I hope you are picking up tips along the way to implement comprehensive scenarios of your own in PowerShell DSC. Please leave questions, comments and suggestions in the Comments section below this article.

Previous Installments

To see the previous installments in this series, visit “100 Days of DevOps with PowerShell”.

2 thoughts on “Day 35: Automating the Steps of PowerShell DSC MOF and Node Configuration

  1. Profile photo of Tommy Gunn

    Pete, I was about to suggest you needed to update a couple of variable names in your script samples, but it seems maybe you already have? or am I going crazy?

    Anyway, works like a champ for me now. Thanks to you and the team for a great series.

  2. Pingback: Powershell DSC – Desired State Control – Resources | DevOpsAut.com

Leave a Reply