It is similar to Azure automation running book jobs, however it doesn’t perform any task except creation of node configuration.
DSC Pull Server
DSC pull server is nothing but a common place where all the node configurations are placed. Each node (machine) in the infrastructure setup polls this pull server to check if it is aligned with its configured state. Once the compilation job runs, the output of it i.e. node configuration is placed on to DSC pull server (it overwrites previous version of node configuration if there is any).
The process can be visualized as below,
Compiling DSC Files
So far we have seen how we can author DSC files mentioning all desired machine configurations in it, we will now see how we can compile those files to generate MOF documents as shown in diagram above.
There are two ways to compile DSC file,
- Using Azure Automation
- Using PowerShell
This article focuses on the first method – i.e. Compiling DSC files using Azure automation service.
Demo
Let’s go ahead and create Azure automation service using new Azure portal. We will name it as demoautomation and will place it under new resource group named as rg-dscdemo
Let’s create a storage account “dscdemostorageacc“ and a VM in same resource group and name it as demo-vm, we will create administrator credentials with user name as DSCAdmin.
Note - this article focuses on Azure DSC and hence creation of VM and its required azure artifacts is not documented in this article, if you want to go through detailed step by step demo of creating a virtual machine in Azure, you can follow this article.
Let’s create out DSC script file with basic configuration to install IIS and ASP.NET framework on the node.
- configuration DSCDemo
- {
- Import-DscResource –ModuleName 'PSDesiredStateConfiguration'
-
- Node "localhost"
- {
- WindowsFeature IIS
- {
- Name = “Web-Server”
- Ensure = “Present”
- }
- WindowsFeature InstallAspDotNet45
- {
- Name = "Web-Asp-Net45"
- Ensure = "Present"
- }
- }
- }
- DSCDemo
Save this file on local machine and upload it to azure automation service using new azure portal.
Once above script is compiled and deployed to desired machines, it will enable IIS role and install ASPNET framework on those machines.
All right, with this let’s move ahead.
Click on the automation service account and you will be navigated to Dashboard.
Click on DSC Configurations tile and upload new script file by clicking add button in header of the blade,
Once it is uploaded, the file will be listed on the DSC Configurations blade. Select the file and click on the compile option from blade header.
Once you click compile, you will be shown a message that “Are you sure you want to compile this configuration? Any node configurations generated will be automatically placed on the Azure Automation DSC pull server. If node configurations with the same name exist on the pull server, they will be overwritten.” – click yes.
It immediately queues a new job for compilation and details can be seen in azure portal. Once the scheduler executes the job, you will see the job status as completed and you can also dive deep into compilation logs, errors and warnings.
Since we have now registered and DSC configuration and compiled it, let’s go ahead and associate our demo-vm with the node configuration. To do this, navigate to the azure automation service account dashboard and click on DSC nodes tile. It will open up a new blade wherein you will be able to add your machines (Cloud VMs or On-Premise).
Let’s click on on Add Azure VM, it will open up a new blade asking to select VM to be registered. Select your VM. Now next step is to select the node configuration you want to apply to a VM, and enter the node name. (You can get the node name from automation service dashboard by clicking on DSC nodes tile.)
After filling in all the required details, once you select ok – the DSC extension gets installed on the selected VM.
Once the VM / node is registered, you will be able to see it under the list of registered VMs in automation service’s dashboard under DSC Nodes.
It shows the status of the VM, right now it is compliant. You can even drill down to the history reports of consistency check of VM.
Once it is completed, you can log on to the VM and verify if it has really installed the configurations on it.
Updating Configuration
To update the configuration of registered nodes at same time, we will simply need to update the configuration file and update appropriate node settings.
Let’s assume that now we need to make sure that all registered nodes should also support .NET Framework 3.5 features (which are currently not installed on our demo VM)
Let’s update configuration file and modify localhost node configurations as below,
- configuration DSCDemo
- {
- Import-DscResource –ModuleName 'PSDesiredStateConfiguration'
-
- Node "localhost"
- {
- WindowsFeature IIS
- {
- Name = “Web-Server”
- Ensure = “Present”
- }
- WindowsFeature InstallAspDotNet45
- {
- Name = "Web-Asp-Net45"
- Ensure = "Present"
- }
- WindowsFeature NET3.5
- {
- Name= "NET-Framework-Features"
- Ensure = "Present"
- }
- }
- }
- DSCDemo
We will follow the same procedure of compilation of DSC script using Azure portal described above.
Once the updated script file is compiled and generated MOF documents are deployed on the pull server, all registered nodes will refer to the new policy and make themselves compliant with it.
Note that Demo VM node status changes to pending.
Once the node starts to update its configuration (based on the node pull frequency interval), the status changes to In Progress.
Once the status changes to Compliant, meaning that node has updated itself with latest provided configurations, we can log on to the VM and check if it has installed the configuration i.e. .NET Framework 3.5 features.
This is all about Azure Automation DSC for now.
Thanks for reading the article, feel free to share your views or comments.