Learn how to harness the power of Azure Virtual Machine Extensions

Do you use Microsoft Azure? Do you have an Azure account? Did you know that you can get one for free here? If you are already an Azure account and you are using the Virtual Machine (VM) services, then I you are at the right place, because in this post I will show you how to take your VMs to the next level with help of VM Extensions.

Azure VM image

VM Extensions are relatively new to Azure. They were announce at the //Build2014 conference and since then there has been a steady growth. Extensions rely on Puppet and Chef. Puppet is a configuration management system and Chef is an automation tool that allows SysOps to automate they way the build, deploy and manage infrastructure. VM Extensions is software that's provided by both Microsoft and third party trusted providers that operates on top of Chef and Puppet and is used to extend the functionality of Azure VMs.

Below is a list of the basic characteristics:

  • Available for both Windows and Linux servers
  • Can be deployed to existing or new VMs
  • Offer programmable support. Sys/DevOps can use a number of tools to manage extensions such as Powershell or xPlatCli. They can still login to the server if they still need to run software locally.
  • Can be templated for future re-usability.
  • Independent update lifecycle with no dependencies on Windows Updates.
  • Enable dynamic composition on a VM. There is no need for static images because extensions are like add-ons that can be added and removed to the template at any point. Long gone are the days when you had to create a brand new image because you missed a feature or there is a need for a new application to be added.

Extensions can be applied either through the portal or through powershell. Some of the third-party ones may require a license key and it's the responsibility of the VM owner to obtain and apply the appropriate license key. The new portal is still playing catch up with the old in terms of available content and this is also evident in the VM extensions area. Some extensions are not present on the new portal but you can still use the old one or powershell to obtain the full list of available extensions.

If your prefer to use the Azure Powershell cmdlets, you need to download the Azure SDK (version 2.5 at the time of writing). The most up to date version can be downloaded here. With the Azure Powershell you can perform the exact same operations that are available in the Azure portal. However, it seems to me that powershell is quite more powerful and much faster when compared to the portal as you don't have to jump through different screens to apply an extension. In addition, you get the added benefit of a script file that can be saved, ammended and checked in to source control for future reuse. For a full list of all the available cmdlets, you can check the documentation.

Let's see a very quick example of the Azure Extensions in Powershell. Open the Azure Powershell command line and type the following:

    # log in to Azure
    # Get a list of all available extensions - verbose
    # Get a list of all available extension - summary
    Get-AzureVMAvailableExtension | fl Publisher,ExtensionName
    # Install the VMAccess extension
    $VM1 = Get-AzureVM -ServiceName "ServiceName" -Name "VMName"
    Set-AzureVMaccessExtension -VM $VM1 –UserName "AdminAccountName" –Password   "NewPassword" –ReferenceName "MyVMAccessAgent" | Update-AzureVM    

You can monitor the progress of your executed scripts through the portal, particularly useful if you are executing a large number of scripts.

No matter which approach you decide to employ, the true beauty of the extensions is the programmability that they offer. Outwith the standard list of extensions, anyone can write and apply his/her own extension in the form of a powershell script. There is a handy "Custom Extension" that takes two parameters: a file and a list of command parameters. The command parameters that accompany the script are optional. A handy use of this extension is the creation of bootstrapper where one master script is responsible for downloading and applying a number of other scripts. Think of Chocolatey NuGet and how you can leverage that script to configure your VM in seconds.

Bonus Tip: Have you ever been in the situation where you created a VM to test something and then you didn't use it for a couple of days/weeks and you forgot your account password? In the good ol' days, your only option would have been to delete the VM and start all over. Now, there is an extension called "VMAccess", that allows you to reset your VM account password! Therefore, if you ever lose that precious VM password, you can use this extension to regain access to your VM - you can thank me later :)

I can see how powerful extensions can be in automating and managing your Azure VM infrastructure especially with the new extensions becoming available every day. Make sure you take advantage of this excellent Azure feature and feel free to contact me if you have any questions regarding the service.

P.S Make sure you follow me on Twitter @christosmatskas for more up-to-date news, articles and tips.

  • Share this post on