0

I'm running through simple exercises to learn Azure and Powershell DSC.

This blog entry provides the perfect "Hello World" example for DSC:

Configuration HelloWorldConfig 
{
       Node localhost 
       {
              File TestFile {
                     Ensure = "Present"
                     DestinationPath = "c:\temp\HelloWorld.txt"
                     Contents = "Hello World!"
              }
       }
}

I created the package using powershell, and uploaded to my Azure VM via the extensions blade on the azure portal.

It worked! When I logged on to the machine, I could see the file c:\temp\HelloWorld.txt.

But DSC is supposed to protect you from 'configuration drift'. To test this, I drifted my configuration by manually deleting the file.

How do I make the file appear again? i.e. How do I re-run this Desired State Configuration check.

I assume that the DSC script I uploaded resides somewhere on the virtual machine. (I can see an entry on the extensions blade).

enter image description here

Or do I have to reload the package? If so, why is that entry even visible on the blade?


I ask, where does this package even reside? I found out the answer using powershell:
$extension = Get-AzureRmVMDscExtension -ResourceGroupName $vm.ResourceGroupName -VMName $vm.Name
$extension.ModulesUrl

This revealed that my package now resides in https://iaasv2tempstoreseasia.blob.core.windows.net/vmextensionstemporary-000116674c9bb772-20160908062048340/sample-dsc-package.zip?sv=2015-04-05&sr=c&sig=YnGCCH%2Bvfv%2FMPWexQWhGOw7H8d8EkGcN5Ufudyz1MIE%3D&se=2016-09-09T06%3A20%3A48Z&sp=rw

So, I interpret it is in a storage account (not mine) called iaasv2tempstoreseasia in a blob container called vmextensionstemporary-000116674c9bb772-20160908062048340. Just the existence of the word temp suggests it's not there to be navigated to.

And interestingly, when I deleted the DSC extension from the Extensions blade, I could still download the package using this URL. After a few hours it went away - I suspect by some cleanup job.

Andrew Shepherd
  • 573
  • 2
  • 6
  • 16

1 Answers1

3

DSC uses the DSC Local Configuration Manager to process you DSC configuration and to monitor it. the Local Configuration Manger has a setting called CONFIGURATION MODE, by default this is set to ApplyAndMonitor. This means that it will process and apply your DSC script but if there is a change (in you example deleting the file) it wont automatically re-apply the settings. what you need to do is set the CONFIGURATION MODE to ApplyAndAutocorrect. in this mode it will detect configuration drift and re-apply your DSC settings.

enter image description here

Check out this URL for more info on this setting:

https://msdn.microsoft.com/en-us/PowerShell/DSC/metaConfig

Michael Brown
  • 3,254
  • 2
  • 11
  • 11
  • Thanks. I logged on to the virtual machine and was able to change the ConfigurationMode parameter from there (after a lot of head scratching). I wonder if you can configure the Local Configuration Manager settings remotely via Azure Automation DSC. – Andrew Shepherd Sep 10 '16 at 10:03
  • @AndrewShepherd you can set the LCM settings in your DSC file, these will then be reflected on the VM. – Sam Cogan Sep 14 '16 at 15:09