1

我已经使用 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'))]"
                    }
                }
            },
4

1 回答 1

-1

实际上,如果您使用 powershell cmdlet,自定义扩展无法同时执行。但可以在模板中设置并一次性执行。

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

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

你可以看看这个链接。这和你很相似。

于 2018-07-26T05:45:50.027 回答