如何在Azure VM上同时运行2个VM自定义脚本扩展

时间:2018-07-26 05:22:01

标签: azure arm-template azure-vm-templates

我已经使用ARM模板创建了Azure VM,并希望在部署VM之后在同一VM上运行2个VM脚本扩展。

如何使用ARM模板?

 {
        "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'))]"
                }
            }
        },

更新:-

当前,我正在使用以下相同的扩展名运行config.sh和config1.sh。但是它正在一个接一个地运行。我希望使用扩展名同时启动config.sh和config1.sh。

{
                "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 个答案:

答案 0 :(得分:-1)

实际上,如果您使用powershell cmdlet,则自定义扩展不能同时执行。但是可以将其设置在模板中并一次执行。

当我看到您的模板时,将两个扩展名设置为相同的名称。您可以更改其中之一。然后像下面这样向其中之一添加一个DependOn:

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

您可以查看此link。和你相似。