Azure ARM Templates Tips and Tricks 5: Custom Script Extension workaround, I cannot add another extension to a VM to run a script on the last node of the cluster

One of the advertised features of Custom Script Extension is to be able to add multiple of those to a VM when needed. Such a need popped up when we were developing some templates like Couchbase.

With Couchbase, after installing the package to all of the nodes, the configuration of cluster needs to start on one single node, to create the cluster and add the other members to it.

During our first try, the natural way was to configure the resources such that, we deploy all of the cluster nodes, and install the package during deployment, then specify another Custom Script extension resource to do the configuration as demonstrated below.

However, what we noticed was although this was not showing any errors, the actual script was not running, because of a potential bug (and yes it is logged).

Our solution was to deploy N-1 nodes first, then deploy the Nth node, with a different set of command line options passed to the shell script that gets passed in, to prompt it to configure the cluster after installing the package.

Let’s see it in action. Following is what gets set to clusterSpec variable

Here, please notice the “installCommand” and “setupCommand” properties of vmScripts variable. Also, notice, “clusterSizeMinusOne”, “clusterSize” and “lastNodeId” variables. At the time of developing this template, the language did not allow arithmetic functions.

Following is the related two deployments in the azuredeploy.json template. First one deploys the N-1 nodes, and uses the “installCommand” for the “commandToExecute” parameter. Second one installs the Nth node and uses “setupCommand” for the “commandToExecute” parameter.

 Next tip