Custom script extention on Azure VMSS

Amine Charot
Charot
Published in
2 min readMar 29, 2019

--

Hello, Let’s see how to run a script inside an Azure Virtual Machine Scale Set already created.

Using Microsoft Azure, it’s easy to administrate virtual machines because of the multiple options such as Microsoft Azure Portal where all you have to do, is to fill the required information to provision some VMs.

It’s a way to do it, but in order to respect the DevOps philosophy to get better results, we should automate the infrastructure deployment too (Infrastructure as a Code). You can use ARM Template to fill out the required input and provision your VMSS.

Once you’ve provisioned your VMSS, you should configure it. Sometimes you may need to execute scripts inside the whole VMs that constructs a VMSS. You won’t connect to each VM and run it manually ! Come on ! The solution is to use the Custom Script Extention which is useful for post-deployment configuration.

  • How to update a VMSS ?

First thing, you need to upload your scripts inside a storage account or Github, then get the URL.

Secondly, you must access to https://resources.azure.com/, look for the VMSS template then add the following snippet :

"properties": {   
"publisher": "Microsoft.Compute",
"type": "CustomScriptExtension",
"typeHandlerVersion": "1.9",
"autoUpgradeMinorVersion": true,
"name" : "chooseAname"
"settings": {
"fileUris":
[
"script location"
],
},
"protectedSettings":
{
"commandToExecute": "myExecutionCommand",
"storageAccountName": "myStorageAccountName",
"storageAccountKey": "myStorageAccountKey"
}
}
  • fileUris : Here you specify the URI of the file.
  • protectedSetting : You must specify the command to execute. In case of a PowerShell script it must be something like :
powershell -ExecutionPolicy Unrestricted -File myscript.ps1

Then your VMSS will pass to an updating state. Wait until it becomes green inside of blue then your script was run !

Bella ciao,

--

--