代码之家  ›  专栏  ›  技术社区  ›  Galet

如何在ARM模板中多次对不同的脚本URI使用相同的扩展

  •  0
  • Galet  · 技术社区  · 6 年前

    我想在创建VM之后运行第一个扩展脚本。然后在部署集群之后,我希望在设置中具有时间戳的同一个虚拟机上运行第二个扩展脚本。但我无法运行第二个脚本。它说错误如下

    操作系统类型“linux”不支持每个处理程序多个vmextensions

    D

    {
        "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,
            "settings": {
               "fileUris": ["[variables('installScript')]"]
            },
            "protectedSettings":{
                "commandToExecute": "[concat('bash config.sh', ' ', parameters('key'))]"
            }
        }
    },
    
    
    
    {
            "type": "Microsoft.Compute/virtualMachines/extensions",
            "name": "[concat(variables('vmName'),'/install-script1')]",
            "apiVersion": "[variables('computeApiVersion')]",
            "location": "[variables('location')]",
            "dependsOn": [
                "[resourceId(parameters('clusterResourceGroupName'), 'Microsoft.Resources/deployments', variables('clusterTemplateName'))]",
                "[resourceId('Microsoft.Resources/deployments', variables('vmTemplateName'))]"
            ],
            "properties": {
                "publisher": "Microsoft.Azure.Extensions",
                "type": "CustomScript",
                "typeHandlerVersion": "2.0",
                "autoUpgradeMinorVersion": true,
                "settings": {
                   "fileUris": ["[variables('installScript1')]"],
                   "timestamp": "123456789"
                },
                "protectedSettings":{
                    "commandToExecute": "[concat('bash config1.sh', ' ', parameters('key1'))]"
                }
            }
        },
    

    更新 -

    我使用以下方法部署集群和虚拟机。但我还是有同样的错误。我已经添加了 强制更新标记 我需要在这个方法中修改什么才能使它工作?

        {
            "apiVersion": "[variables('resourceDeploymentApiVersion')]",
            "name": "[variables('clusterTemplateName')]",
            "type": "Microsoft.Resources/deployments",
            "resourceGroup": "[parameters('clusterResourceGroupName')]",
            "properties": {
                "mode": "Incremental",
                "templateLink": {
                    "uri": "[variables('clusterTemplateURL')]"
                },
                "parameters": {},
            }
         },
         {
            "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-script1')]",
                "apiVersion": "[variables('computeApiVersion')]",
                "location": "[variables('location')]",
                "dependsOn": [
                    "[resourceId(parameters('clusterResourceGroupName'), 'Microsoft.Resources/deployments', variables('clusterTemplateName'))]",
                    "[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'))]"
                    }
                }
            },
    
    1 回复  |  直到 6 年前
        1
  •  1
  •   4c74356b41    6 年前

    您可以通过嵌套部署来实现这一点。因此,您需要使用脚本扩展创建一个VM,并创建一个嵌套的部署。嵌套部署需要依赖于要完成的扩展。嵌套部署将只是另一个资源(microsoft.compute/virtualmaches/extensions),并且 它必须与前一个脚本扩展名同名 还有一个不同的 forceUpdateTag . 这样就可以了。

    需要此解决方法,因为一个VM只能有每个扩展类型的一个副本。这样,您就可以用新值更新扩展,并强制它使用 强制更新标记 .

    工作示例:
    https://paste.ee/p/4mOiI -仅带脚本扩展名的嵌套模板
    https://paste.ee/p/nG7XV -父模板