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

标签 azure azure-rm-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'))]"
                    }
                }
            },

最佳答案

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

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

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

你可以看看这个link 。跟你很像。

关于azure - 如何在 Azure VM 上同时运行 2 个 VM 自定义脚本扩展,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51531526/

相关文章:

azure 虚拟机创建失败

azure - 从现有 VHD 创建 Azure VM,无需使用 powershell

azure - 带有空格参数的 ARM 模板自定义脚本扩展

azure - 如何使用 ARM 模板为注释创建 Application Insights API key

azure - 我们可以在管理组级别拥有用户身份吗?

Azure部署源,选择启动项目来构建

.net - Azure Web 角色如何在没有入口点的情况下运行?

Azure ML Workbench Kubernetes 部署失败

azure - 有没有办法以完整模式部署 "nested"或 "tiered"资源(即服务总线队列)或达到等效结果?