Share →
Buffer

From the last four posts in this series, I have explained the DSC foundation corner stone of the what, why, where and how.

Powerbit BlocksWith a good foundation of the basic to work from, we now can go deeper into DSC authoring phases.  The authoring phase is the first part of a two-part phase.  The Pull and Push modes is the second phase that deserves a blog post on its own.

What I will be covering in this post:

The fundamentals of the DSC authoring phase. The creation of the .MOF file for our target server

What I will not be covered in this post:

In-depth detail on the DSC build in resources and how to use them.  The following link contains more information on the DSC resources

Windows PowerShell Desired State Configuration Resources

The Staging Phase of a Pull and Push mode

Goal of the post:

To gain a base understanding of the Authoring phases of the DSC workflow

The info:

As we begin to break down the DSC workflow, we need to identify the different phases that the DSC has.  The Configuration Authoring and Staging phase and the Configuration Enacting phase.

Flow

Figure 2 from Windows PowerShell Desired State Configuration Revealed 

Below is a short description of the two major phases.

  • Configuration Authoring and Staging Phase: The creation of the Management Object Format (.MOF) file/s to be deployed to a target server.  The staging part of the phase refers to the “Staging” location of the authoring artifacts. This can be a shared folder or part of a NuGet package.
  • Configuration Enacting Phase: The execution of the MOF file on the target server by either a Pull or Push mode

To get started with the Authoring and Staging phase, we need to create a .MOF file for our target environment. We can create the .MOF file/s in a number of different methods, from NotePad to 3rd party tools. I will be using the PowerShell ISE for my scripting tool.

On a side note, all final scripts should go into a code repository and not on your local machine.  Yes, I also have a number of scripts on my local machine, but all “production” scripts are in source control for others to update and to view history.

First, let’s make sure we have everything we need and setup on what I’m calling the “working” machine.

Open the PowerShell command and type in the following:

Get-DscResource -name  W*

name W*

 

Figure 3

 

By using the wildcard W* the output will display all the resource starting with W. This is handy when you don’t know the full name of a resource you have on “working” machine.

If you plan to do any automation through a build system, you will need to make sure that the build agent or “working” machine” has the resources installed.

Let us take a closer look at the “WindowsFeature” properties by typing the following into the PowerShell ISE:

Get-DscResource -name  Windowsfeature -Syntax

Syntax

 

Figure 4

The WindowFeatures properties provides options that we can use for a simple server build out.  For example, the Ensure indicates if the role or feature is present or absent. The DependsOn indicates that the configuration of another resource must run before this resource is configured. With these two simple properties, we can do a lot for a server build out.

Now that we have verified that the build-in DSC features (Windows PowerShell 4.0) exist on the “working” machine. We can move on to creating the .MOF file for the target server.

Open the PowerShell ISE and add the following:

Configuration WebsiteConfig

{

Node WSR2-1

{

WindowsFeature WebServer1

{

Name = “Web-Server”

DependsOn = “[WindowsFeature]ASP”

}

WindowsFeature ASP

{

Name = “Web-ASP-Net45”

}

}

}

WebsiteConfig

Figure 5

Figure 5

We now have created our first .MOF file that will install the .Net4.5 framework for a target machine.

Let us look at the .MOF file that we created.  Since I change my path to C:\PS when I executed the above script. The .MOF file will be the folder called C:\PS\WebsiteConfig and the WSR2-1.MOF will be the name of the Node keyword from the script we just executed.

Figure 6

Figure 6

As you look at the .MOF file you will notice the top and bottom part has information on who, when and where the script was created

/*

@TargetNode=’WSR2-1′

@GeneratedBy=BRoot

@GenerationDate=12/31/2014 12:31:30

@GenerationHost=B4ROOTWIN8E

*/

As the .MOF enters into the instance part, it defines the source and module information.  One item to point out is the DependsOn section. Since I have added the DependsOn condition, at execution time, in this case the script will look for that ASP feature and will return a true or false status. If it exist on the target server the new features will be added, if not, then ASP feature will be installed.

instance of MSFT_RoleResource as $MSFT_RoleResource1ref

{

SourceInfo = “::10::5::WindowsFeature”;

ModuleName = “PSDesiredStateConfiguration”;

ModuleVersion = “1.0”;

ResourceID = “[WindowsFeature]WebServer1”;

Name = “Web-Server”;

DependsOn = {

“[WindowsFeature]ASP”};

ConfigurationName = “WebsiteConfig”;

};

instance of MSFT_RoleResource as $MSFT_RoleResource2ref

{

SourceInfo = “::16::5::WindowsFeature”;

ModuleName = “PSDesiredStateConfiguration”;

ModuleVersion = “1.0”;

ResourceID = “[WindowsFeature]ASP”;

Name = “Web-ASP-Net45”;

ConfigurationName = “WebsiteConfig”;

};

instance of OMI_ConfigurationDocument

{

Version=”1.0.0″;

Author=”BRoot”;

GenerationDate=”01/03/2015 12:42:29″;

GenerationHost=”B4ROOTWIN8E”;

Name=”WebsiteConfig”;

};

Once we have the .MOF generated, we can then push the configuration change to a target system by using the Start-DscConfiguration cmdlet.

Start-DscConfiguration -Path “C:\PS\WebsiteConfig\” -Wait -Verbose

This is where I’m going to leave off for now.  The deployment of the scripts created in the authoring and staging phase is the another large topic and will be next post in the series.

Conclusion:

In this post, we began the deeper dive into the DSC, defining the two phases, Configuration Authoring/Staging, and Configuration Enacting that make up the workflow.  We briefly covered how to create a new MOF file that contains a DependOn feature and what the .MOF file looks like.  While there is more to discuss on the Authoring/Staging phase, the goal of the post is to introduce the Authoring and Staging concepts.  The authoring resource links below will provide more information on the authoring/staging phase.

Authoring Resources:

Hungry for more Windows PowerShell Desired State Configuration Resources?

Resource Designer Tool – A walkthrough writing a DSC resource

Want to secure credentials in Windows PowerShell Desired State Configuration?

 

Print Friendly
Tagged with →