AzureDSC

If there was one thing that resonated loudly at TechEd 2014, it was the fact that IT professionals were the cornerstone in regards to the user / developer trifecta in the enablement of DevOps and the adoption of the cloud.  What's more, our current knowledge of on premise deployment and management will be of great importance in making this happen.  What’s more, IT professionals have a gift of doing more with less. No matter if it is less time or less resources, system administrators and IT manager alike always find away.  It is part of the reason why we at CANITPRO.NET advocate PowerShell so often and the reason why the word “Power” is enrolled in the offering.

Microsoft MVP Sean Kearny, one of Canada’s resident experts on PowerShell, has provided many posts on enabling PowerShell Desired State Configuration via on premise systems. This post will extend that knowledge to the cloud. As you are aware, PowerShell Desired State Configuration (DSC) allows for a configuration platform built into Windows based on open standards. When provided to a DevOps initiative, this allows for the flexibility to function consistently and reliably in each stage of the deployment lifecycle.

DSC provides a powerful way to manage both on-premise and cloud environments by introducing a easy declarative syntax into the PowerShell language. Simply describe your environment's desired state via this new declarative syntax, and then distribute it to each target node. The DSC syntax is declarative, making authoring and maintaining configuration for both on-premise and cloud environments simpler.

This Step-By-Step post borrows an example provided by Jeffery Snover and the PowerShell team at TechEd 2014. The provided steps will allow you to provision a virtual machine via a Windows Azure account, upload the configuration defined in myConfigScript.ps1 and the DscBoot.ps1 script to blobs located in your Azure storage account. Once the virtual machine has been provisioned, the Azure script handler extension will download and run DSCBoot.ps1 to envoke the configuration specified in MyConfigScript.ps1.

Prerequisites
 

  1. Ensure you have an active Microsoft Azure subscription
     
  2. Download and install the latest version of Microsoft Azure PowerShell
  3. Install Microsoft Azure Cross Platform Command Line tools after the installation of Microsoft Azure PowerShell
     
  4. Download the AzureBootAgentPowerShellDSCexample.zip file and extract it to a known or common directory
     
    Note: The included MyConfigScript.ps1 uses the
    OneGet package management toolkit and DSC to configure the applications installed on the VM, and creates an IIS website.

Step 1: Setup

  1. Download and save the .publishsettings file to a known location
     
  2. Run the following command in Powershell, replacing $publishSettingsFile with the file name:

    Import-Module azure; Import-AzurePublishSettingsFile -PublishSettingsFile $publishSettingsFile
     

  3. Run the following command and take note of the SubscriptionName result

    Get-AzureSubscription
     

  4. Create a new Azure storage account by running the following command in PowerShell, replacing “demostorage001” with a unique identifier should you not already have an Azure storage account

    New-AzureStorageAccount -storageaccountname demostorage001 -location "East US"
     
    Note: Be sure to utilize the location closest to your region

  5. Get secondary storage key for your storage account
     
  6. Run the following command in PowerShell, replacing “demostorage001” with your storage account name:
     
    Get-AzureStorageKey demostorage001
     
    Note: Storage account names can only contain lowercase letters, numbers or “-“, and must start with a letter
     
  7. Open config.ps1 in PowerShell ISE and change the value of the variable below to point to the .publishsettings file

    $publishSettingsFile = "<your.publishsettings>"
     

  8. Change the value of the variable below to reflect the SubscriptionName property

    $subscriptionName = ""
     

  9. Change the two variable assignments below to reflect your storage account and key
     
    $AccountName = "demostorage"
     
    $AccountKey = "<your-account-key>"
     

Step 2: Testing the Demo

  1. Ensure that config.ps1 has been correctly set up and, the $vmName value is unique
     

$vmName = "<myUserid-machineName-01>"
 
$VMServiceName =
"<myUserid-serviceName-01>"
 
Note: $VMServiceName will report an error should it not be unique
 

  • Open demo.ps1 and follow the steps it contains to see how the VM is created and configured
     
  • Create your own username/password for the VM
     
  • Connect to the Azure Management Portal  and select the Virtual Machines slice
     
  • Find the VM recently created by name and wait for the VM to be “Ready OR Stopped”
     
  • Connect on to the VM with the credentials created in demo.ps1
     

Once completed, verify that the configuration has been properly applied on the target VM. Also ensure that all prescribed browsers and vim / sysinternals packages have been installed, and that the Fourth Coffee website has been created.  To continue learning more DevOps enablement, visit Microsoft Virtual Academy and check out Jump Start: DevOps for IT Pros.