How To Use Configuration Data With Desired State Configuration (DSC)
Think you can do better? Show us!
A good way to handle DSC scaling, is to use DSC configuration data. This will help you separate the “what” from the “how”. In this video, Matt shows us how to separate data from a DSC configuration and place it into configuration data.
Today I'd like to talk to you about how to use configuration data with desired state configuration in my other video? How to write a simple DSC configuration. I started building a DSC configuration for a Web server. This was a good way to get introduced to DSC configurations. However, as we add to that configuration. It will require more typing probably copying and pasting especially if we want to add this configuration to more servers. We may even want to configure non web servers as well. A good way to handle this scaling is to use DSC configuration data with configuration data you can separate the What from the how. Let me explain. In my first example, I have my configuration data stored in a PS one file as a hashtable called configuration data. The configuration data. Hashtable is required to have at least one key named all nodes. You can also use what is called non no data but for now, I'm going to leave that blank. Under my all nodes key I'm storing an array of hash tables. Each hash table has a node name and a role. We're going to use this to dynamically build our DSC configuration if I open the configuration for this example. I have now split the configuration into 2 sections. First time filtering where the role equals web server in this section. I am installing the windows features for my web server in my hello world file. I've also added a resource to add a log file to a folder on the C drive. In the second section. I'm filtering where the role is file server that I'm installing the file and storage services feature and the same log file from before after loading that config one into memory. I'm going to dot source my configuration data file. When we look at our configuration data variable now we can see are all nodes. An non no data. Now, we just need to run our config one configuration and use the configuration data parameter to pass our configuration data variable. This will create our 3 MOFs for our web and file servers now when we need to scale out to more servers. We don't need to touch the actual configuration anymore and less. We need to add more resources to configure to add more servers. We just need to edit our config data then run the configuration against it. Now let's check out my next config data file here. I'm going to utilize the. No data for this. I'm going to use a hash table with the path type and ensure values that I want in my configuration. This information is going to be the same no matter what the server role is so. No data will be a good spot for it. Now let's take a look at the second configuration, you'll notice that I've replaced the values for the log file resource with the configuration data variable further separating the What from the How I'm going to dot source. The second config data file and let's take a look at that configuration data variable again. You can see that we now have a value in. non Node data and we can drill down into it to see our values. These are the values that I want to specify in my configuration. Now, if I run this configuration and we take a look at a MOF that is created we can see all our log file values. In my final example, I'd like to take the. Non Node data a little further you may notice that I no longer have a value in here called. Non Node data that is because non node data isn't actually required to be called. No data you can call it whatever you want and have as many as you want here. I have renamed. No data to log file info, which is a lot more descriptive. I also have 2 more called Web server. Windows feature and file server. Windows feature that is where I'm going to store the windows features that I want to install for? So, in an array. Now let's take a look at the configuration. I still have my web server, an file server sections. But this time for my windows feature resource instead of having to type them all out. I'm using for each to go through each value in my web server in file server. Windows features and dynamically building. The list separating the what from the how in requiring less typing for any long lists of features, I may want to pass. Now let's run this configuration and take a look at them off file for server one. The MOF file has both the Web Server in Windows Auth features. And that is how to use configuration data with desired state configuration.