So with the release of the Azure Resource Manager and all its glory, Microsoft was kind enough to update its CLI as well with Azure Service Management mode and Azure Resource Management mode.
This post is a short and sweet post about how you can create multiple vm instances from some of the built in Azure machine templates in just a few lines of bash.
First off you can read my post on how to install and use the azure cli here
Now, to get to know the options you have available to play with, you need locations and publishers first, so you can add them into the scriptsazure location list
Now you can get a list of available image publishers in a region.
azure vm image list-publishers northeurope
You can then get a list of available images for that publisher in that region. azure vm image list northeurope Canonical
With the basics for the azure create command covered, we can get into the automation side.
You can create a simple bash script in your editor of choice like so
#!/bin/bashIMAGENAME=`azure vm image list |grep -i Ubuntu-12_04_5-LTS-amd64-server |tail -1 | awk ‘{print $2}’`PASSWORD=”AtotallySECRET!PA55W0RD”echo Password is $PASSWORDazure vm create -e -z “ExtraSmall” -l “West Eurdelope” $1 $IMAGENAME azureuser “$PASSWORD”
To explain what the above does, it first queries Azure to find out a list of images that are available, it then pipes that into the variable $IMAGENAME which we use to create the VM further along in the script. The reason we do this is so that we can choose which version of Linux we want without having to be too accurate on the image name, it will find it and correct us 🙂
We can then run the command multiple times to create multiple VM’s and change the plans/sizes of the VM instances.