问题
I have create a Azure VM using ARM template and want to run a 2 VM script extensions on the same VM after VM is deployed.
How can I achieve using the ARM template?
{
"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-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.1",
"settings": {
"fileUris": ["[variables('installScript1')]"]
},
"protectedSettings":{
"commandToExecute": "[concat('bash config1.sh', ' ', parameters('key1'))]"
}
}
},
Update:-
Currently I am running config.sh and config1.sh in the same extension as below. But it is running one after another. I want both config.sh and config1.sh to be started at same time using the extension.
{
"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.1",
"settings": {
"fileUris": ["[variables('installScript1')]"]
},
"protectedSettings":{
"commandToExecute": "[concat('bash config1.sh', ' ', parameters('key1'), ' ', '&&', ' ', 'bash config.sh', ' ', parameters('key'))]"
}
}
},
回答1:
Actually, the custom extension cannot execute at the same time if you use powershell cmdlet. But it can be set in a template and execute at one time.
When I see your template, you set the two extensions with the same name. You can change one of them. Then add a dependsOn to one of them just like this:
"dependsOn":[
"[concat('Microsoft.Compute/virtualMachines/', variables('vmName'),'/', 'install-script')]"
],
You can take a look at this link. It's similar to you.
来源:https://stackoverflow.com/questions/51531526/how-to-run-a-2-vm-custom-script-extensions-on-azure-vm-at-the-same-time