Adding and using the DSC For Linux VM Extension to Azure Stack TP1

In my previous post I described how to add a CentOS image to Azure Stack so tenants can deploy Linux machines.
Now that we have an image available, it’s time for the next step. Deploy a Linux VM and have DSC configure it!

Acquire the DSC For Linux VM Extension

VM Extensions are handled by the CRP which offers up the extensions located in the C:\ClusterStorage\Volume1\Share\CRP\GuestArtifactRepository directory.


If you look closely, you probably notice that the DSC For Linux VM extension is not present. It did not ship with Azure Stack TP1.
So how to make it available? The extension is available on GitHub but to spare you the trouble I had, don’t download it here.
I got it to work but once the VM was installing the extension, thing started to break down and unknown errors were thrown.


When investigating the issue, I noticed the extension was present on the VM in zipped up form. I figured I would deploy a VM in Azure and see if I could acquire the extension that way.
Bingo! To safe you the trouble from doing the same, I’ve put the extension on my GitHub for you to download. I did not notice any obvious differences between the version used in Azure and the one I got from the Azure GitHub repo but the end result is that the one I got from Azure worked.

Once downloaded from my GitHub you need to make the extension available for the CRP by placing the file in zipped up form at C:\ClusterStorage\Volume1\Share\CRP\GuestArtifactRepository.
Make sure to unblock it!


You could also run this script to have it done in one go:

The extension is now available.

Prepping a configuration

Because PowerShell does not run on Linux, the DSC For Linux extension is not able to compile PowerShell DSC Configuration scripts into MOF files.
Instead you need to use the DSC For Linux extension with pre-compiled MOF or meta.MOF files.

First let’s create a configuration script and compile a MOF file from it. All following actions take place on the client VM.

This script will download the NX DSC Resource Module first so PowerShell will be able to compile the MOF. Next, a configuration is loaded which will make the Linux box into a webserver.
Finally, the configuration is called and compiled by PowerShell. The simple HTML code declared in the WebSite variable will be passed to the configuration parameter. The resulting MOF can be found at to C:\NginX\localhost.mof.

Now we have a configuration for a Linux box we need to make sure that the DSC For Linux Extension can get to it when the VM gets deployed. To do this, I’ll create a Storage Account to contain the MOF file so the extension can download it from there. The extension can deal with storage accounts natively but for this demo I simulate the MOF file to be located on a publicly available Uri.
When running the script you should modify the TenantUser variable on line 2.

The script will figure out the Tenant Id based on the domain name used to authenticate. Then it will add Azure Stack as an environment for PowerShell cmdlets to use.
It will authenticate and while doing so, it will select the Azure Stack environment just added as the context. Finally, a storage account is created containing an anonymously accessible container.
The mof file compiled earlier will be uploaded to the container and the Uri on which it is available will be printed out (copy this as we need it later, https://linuxdsc.blob.azurestack.local/mof/localhost.mof).

Using the DSC For Linux VM Extension

Now everything is in place we can provision a VM and use the DSC For Linux extension with it to finalize the VMs configuration during creation.
The easiest way is to do this is through a JSON template as the VM extension needs name resolution for the extension to work properly (in current TP1 we need to explicitly configure DNS).

Copy the following template and save it on the ClientVM on the root of C:\. Name it DeployVMWithDSCForLinux.json. If you followed my blogpost on adding CentOS to Azure Stack and changed the publisher name for example, you need to adjust this template accordingly!

Next, run the following script from the PowerShell session you used earlier. If you close it, please run the region “add AzureStack environment” again.
You should change the MofFileUri if you modified the previous script and you could of course assign your own username and password!

Once the template is deployed you should see similar output as the following:


When you navigate to the uri stated in the Outputs you should see the WebPage hosted by NginX!


When navigating to the VM extensions via the portal, you should see the extension status as succeeded as well.


Alternatively from a JSON template. You could also use PowerShell to  add the extension to an already existing VM. This would look something like this:

Note that Get-AzureRmVMExtensionImage currently does not work against Azure Stack so it could be a little bit tough to figure out all the data you need to specify.

Alternatively from a PowerShell invoked deployment, you could also copy paste the template content into the Template Deployment widget and go from there.


Hope you enjoyed reading !

Spread the word. Share this post!