1
votes

I have python script1.py and bash script script2.sh to run after VM is created through ARM template using below snippet. For some reason when I add this script2.sh VM creation fails. 'fileUris' as well as commandToExecute are correct. What could be the reason , and where to look for errors ?

{
              "name": "[concat(variables('web'),'/script1')]",                                
              "properties":
               {                   
                    "settings": {
                        "fileUris": ["https://.../script1.py"],
                        "commandToExecute": "python script1.py"
                   }
              }
          },
     {
              "name": "[concat(variables('web'),'/script2')]",                                                 
              "properties":
               {                
                    "settings": {
                        "fileUris": ["https://.../script2.sh"],
                        "commandToExecute": "bash script2.sh"
                   }
              }
          },

I ommit type, apiVersion, location as well as publisher, type and typeHandlerVersion for clarity. Both scripts depend on "[concat('Microsoft.Compute/virtualMachines/', variables('web'))]"

1

1 Answers

2
votes

For Azure VM extension, it's an Azure resource, not the property of a resource. So if you want to add the multi extensions to the VM in one template, you should make each extension as one resource. Here is the example.

update

And if there are two or more extensions in one template, you should make sure the order of the extensions to execute. Although multi extensions in one template, they are still executing one by one in the VM.

For example, the first extension named

"[concat(variables('vmName'),'/', 'antiMalwareExtension')]"

and you need to add "dependsOn" in the second extension:

"dependsOn":[  
     "[concat('Microsoft.Compute/virtualMachines/', variables('vmName'))]",
     "[concat('Microsoft.Compute/virtualMachines/', variables('vmName'),'/', 'antiMalwareExtension')]"
  ],

The extensions after also should do like this.