How to run a 2 VM custom script extensions on Azure VM at the same time

≯℡__Kan透↙ 提交于 2019-12-24 07:15:37

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!