0

I want to run first extension script after VM is created. Then after cluster is deployed and I want to run a second extension script on the same VM with timestamp in settings. But I am unable to run a second script. It says errors as below

Multiple VMExtensions per handler not supported for OS type 'Linux

d

{
    "type": "Microsoft.Compute/virtualMachines/extensions",
    "name": "[concat(variables('vmName'),'/install-script')]",
    "apiVersion": "[variables('computeApiVersion')]",
    "location": "[variables('location')]",
    "dependsOn": [
        "[resourceId('Microsoft.Resources/deployments', variables('vmTemplateName'))]"
    ],
    "properties": {
        "publisher": "Microsoft.Azure.Extensions",
        "type": "CustomScript",
        "typeHandlerVersion": "2.0",
        "autoUpgradeMinorVersion": true,
        "settings": {
           "fileUris": ["[variables('installScript')]"]
        },
        "protectedSettings":{
            "commandToExecute": "[concat('bash config.sh', ' ', parameters('key'))]"
        }
    }
},



{
        "type": "Microsoft.Compute/virtualMachines/extensions",
        "name": "[concat(variables('vmName'),'/install-script1')]",
        "apiVersion": "[variables('computeApiVersion')]",
        "location": "[variables('location')]",
        "dependsOn": [
            "[resourceId(parameters('clusterResourceGroupName'), 'Microsoft.Resources/deployments', variables('clusterTemplateName'))]",
            "[resourceId('Microsoft.Resources/deployments', variables('vmTemplateName'))]"
        ],
        "properties": {
            "publisher": "Microsoft.Azure.Extensions",
            "type": "CustomScript",
            "typeHandlerVersion": "2.0",
            "autoUpgradeMinorVersion": true,
            "settings": {
               "fileUris": ["[variables('installScript1')]"],
               "timestamp": "123456789"
            },
            "protectedSettings":{
                "commandToExecute": "[concat('bash config1.sh', ' ', parameters('key1'))]"
            }
        }
    },

Update:-

I am deploy Cluster and VM using the following approach. Still I get same error. I have added forceUpdatetag What I need to modify in this approach to make it to work?

    {
        "apiVersion": "[variables('resourceDeploymentApiVersion')]",
        "name": "[variables('clusterTemplateName')]",
        "type": "Microsoft.Resources/deployments",
        "resourceGroup": "[parameters('clusterResourceGroupName')]",
        "properties": {
            "mode": "Incremental",
            "templateLink": {
                "uri": "[variables('clusterTemplateURL')]"
            },
            "parameters": {},
        }
     },
     {
        "apiVersion": "[variables('resourceDeploymentApiVersion')]",
        "name": "[variables('vmTemplateName')]",
        "type": "Microsoft.Resources/deployments",
        "resourceGroup": "[parameters('vmGroupName')]",
        "properties": {
            "mode": "Incremental",
            "templateLink": {
                "uri": "[variables('vmTemplateURL')]"
            },
            "parameters": {},
        }
     }
 {
        "type": "Microsoft.Compute/virtualMachines/extensions",
        "name": "[concat(variables('vmName'),'/install-script')]",
        "apiVersion": "[variables('computeApiVersion')]",
        "location": "[variables('location')]",
        "dependsOn": [
            "[resourceId('Microsoft.Resources/deployments', variables('vmTemplateName'))]"
        ],
        "properties": {
            "publisher": "Microsoft.Azure.Extensions",
            "type": "CustomScript",
            "typeHandlerVersion": "2.0",
            "autoUpgradeMinorVersion": true,
            "forceUpdateTag": "v.1.0",
            "settings": {
               "fileUris": ["[variables('installScript')]"]
            },
            "protectedSettings":{
                "commandToExecute": "[concat('bash config.sh', ' ', parameters('key'))]"
            }
        }
    },



    {
            "type": "Microsoft.Compute/virtualMachines/extensions",
            "name": "[concat(variables('vmName'),'/install-script1')]",
            "apiVersion": "[variables('computeApiVersion')]",
            "location": "[variables('location')]",
            "dependsOn": [
                "[resourceId(parameters('clusterResourceGroupName'), 'Microsoft.Resources/deployments', variables('clusterTemplateName'))]",
                "[resourceId('Microsoft.Resources/deployments', variables('vmTemplateName'))]"
            ],
            "properties": {
                "publisher": "Microsoft.Azure.Extensions",
                "type": "CustomScript",
                "typeHandlerVersion": "2.0",
                "autoUpgradeMinorVersion": true,
                "forceUpdateTag": "v.1.1",
                "settings": {
                   "fileUris": ["[variables('installScript1')]"]
                },
                "protectedSettings":{
                    "commandToExecute": "[concat('bash config1.sh', ' ', parameters('key1'))]"
                }
            }
        },
Galet
  • 5,853
  • 21
  • 82
  • 148

1 Answers1

1

You can do this with nested deployments. So you need to create a vm with script extension and create a nested deployment. That nested deployment needs to depend on the extension to finish. The nested deployment will be just another resource (Microsoft.Compute/virtualMachines/extensions) and it has to have the same name as the previous script extension and a different forceUpdateTag. that way it will work.

this workaround is needed because a VM can only have 1 copy of each extension type. this way you update the extension with new values and force it to rerun with forceUpdateTag.

working example:
https://paste.ee/p/4mOiI - nested template with scriptextension only
https://paste.ee/p/nG7XV - parent template

4c74356b41
  • 69,186
  • 6
  • 100
  • 141
  • Kindly look at updated question. Still I get issue after added forceUpdateTag in template – Galet Jul 23 '18 at 08:06
  • like i said, it should be in a separate deployment, not in the same template. if you are doing that, i cant really understand the update – 4c74356b41 Jul 23 '18 at 08:09
  • Here are the steps my ARM templates do:- 1. Create Cluster using Microsoft.Resources/deployments and reference templateLink using external URL 2. Create VM using Microsoft.Resources/deployments and reference templateLink using external URL 3. Run script on VM after [2] is completed, depends on [2] 4. Run script on VM after [1] is completed, depends on [1] and [2]. Let me know if you are not clear? – Galet Jul 23 '18 at 08:55
  • 4 should depend on 3 and should be a nested deployment, everything else can be in the same deployment (for the purpose of the question) – 4c74356b41 Jul 23 '18 at 08:57
  • [3] will be completed before [4] start, because [1] will take more time to complete. Ok. I will add it. Do you this that's why forceUpdateTag is not working? – Galet Jul 23 '18 at 09:00
  • i dont know about other parts of your template, i'm only talking about how to make 2 script extensions work on the same vm. second extension should depend on the first one. – 4c74356b41 Jul 23 '18 at 09:02
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/176546/discussion-between-karan-and-4c74356b41). – Galet Jul 23 '18 at 09:03
  • How to run a 2 extensions at the same time on the VM. – Galet Jul 26 '18 at 04:39
  • you really should start a new question – 4c74356b41 Jul 26 '18 at 04:42
  • @ 4c74356b41 Started a new question https://stackoverflow.com/questions/51531526/how-to-run-a-2-vm-custom-script-extensions-on-azure-vm-at-the-same-time – Galet Jul 26 '18 at 05:22
  • @4c74356b41 These paste.ee links are not working. – Jaydeep Soni Dec 29 '21 at 11:59
  • sorry, i don't have the code lying around anymore, but the idea is the same. have a regular extension on the vm and then have a nested\linked deployment that depends on the extension and redeploys the extension with the new parameters\settings (you need to use `forceUpdateTag` for that) – 4c74356b41 Dec 30 '21 at 13:25