【问题标题】:Disable Windows Updates in Azure Resource Manager Template for Virtual Machine deployment在用于虚拟机部署的 Azure 资源管理器模板中禁用 Windows 更新
【发布时间】:2016-04-11 15:15:16
【问题描述】:

我想为基于 ARM 模板的 VM 部署禁用“Windows 更新”。我找到了一个相关的设置enableAutomaticUpdatesin a recent Microsoft.Compute provider schema。但我没有找到任何使用此设置的 ARM 模板。我搜索了几个与 Windows VM 部署相关的Azure Quickstart templates - 但它们都没有打算在配置时控制 Windows 更新服务的行为。我知道 CLASSIC 部署模型可用的选项,但我明确地在寻找解决方案 using Azure Resource Manager Deployment model

{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",

...

{
  "apiVersion": "2015-06-15",
  "type": "Microsoft.Compute/virtualMachines",
  "name": "[parameters('vmName')]",
  "location": "[parameters('vmLocation')]",
  "tags": {
    "displayName": "VirtualMachine"
  },
  "dependsOn": [
    "[concat('Microsoft.Storage/storageAccounts/', parameters('vmStorageAccountName'))]",
    "[concat('Microsoft.Network/networkInterfaces/', variables('nicName'))]"
  ],
  "properties": {
    "hardwareProfile": {
      "vmSize": "[parameters('vmSize')]"
    },
    "osProfile": {
      "computerName": "[parameters('vmName')]",
      "adminUsername": "[parameters('adminUsername')]",
      "adminPassword": "[parameters('adminPassword')]"
    },
    "windowsConfiguration": {
      "enableAutomaticUpdates": false        
    },
    ...

我尝试在现有 ARM 模板中使用属性 windowsConfiguration 会导致部署失败并出现此错误消息(显示在 Azure 门户中)。

在类型的对象上找不到成员“windowsConfiguration” '特性'。路径“properties.windowsConfiguration”,第 1 行,位置 259.(代码:BadRequest)

当我将 Microsoft.Compute 升级到版本 2015-08-01 时,尝试引用包含配置属性 enableAutomaticUpdates 的架构,VM 部署失败并显示此错误消息。显然我做错了什么。

{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",

...

{
  "apiVersion": "2015-08-01",
  "type": "Microsoft.Compute/virtualMachines",
  "name": "[parameters('vmName')]",
  "location": "[parameters('vmLocation')]",
  "tags": {
    "displayName": "VirtualMachine"
  },
  "dependsOn": [
    "[concat('Microsoft.Storage/storageAccounts/', parameters('vmStorageAccountName'))]",
    "[concat('Microsoft.Network/networkInterfaces/', variables('nicName'))]"
  ],
  "properties": {
    "hardwareProfile": {
      "vmSize": "[parameters('vmSize')]"
    },
    "osProfile": {
      "computerName": "[parameters('vmName')]",
      "adminUsername": "[parameters('adminUsername')]",
      "adminPassword": "[parameters('adminPassword')]"
    },
    "windowsConfiguration": {
      "enableAutomaticUpdates": false        
    },
    ...

未找到位置“西欧”和 'virtualMachines' 类型的 API 版本 '2015-08-01'。支持的 api 版本是 '2015-05-01-preview, 2015-06-15, 2016-03-30'。这 支持的位置是 'eastus、eastus2、westus、centralus、 中北部, 中南部, 北欧, 西欧, 东亚, 东南亚、japaneast、japanwest、australiaeast、 澳大利亚东南部、巴西南部”。 (代码:NoRegisteredProviderFound)

我正在寻求一些指导,如何编写使用 Azure Compute Provider schema version 2015-08-01 在配置时禁用 Windows 更新的 ARM 模板。我的 .NET 解决方案使用 Azure SDK 2.7.1。

【问题讨论】:

    标签: azure-virtual-machine azure-resource-manager


    【解决方案1】:

    我非常接近解决方案。我只是误解了架构。 According to this part of the schema windowsConfiguration is part of osProfile。如果 ARM 模板是这样编写的,Azure 资源管理器会理解我想要什么并在预配时禁用 AutomaticUpdates。

    {
      "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
      "contentVersion": "1.0.0.0",
    
    ...
    
    {
      "apiVersion": "2015-06-15",
      "type": "Microsoft.Compute/virtualMachines",
      "name": "[parameters('vmName')]",
      "location": "[resourceGroup().location]",
      "tags": {
        "displayName": "VirtualMachine"
      },
      "dependsOn": [
        "[concat('Microsoft.Storage/storageAccounts/', parameters('vmStorageAccountName'))]",
        "[concat('Microsoft.Network/networkInterfaces/', variables('nicName'))]"
      ],
      "properties": {
        "hardwareProfile": {
          "vmSize": "[parameters('vmSize')]"
        },
        "osProfile": {
          "computerName": "[parameters('vmName')]",
          "adminUsername": "[parameters('adminUsername')]",
          "adminPassword": "[parameters('adminPassword')]",
          "windowsConfiguration": {
            "enableAutomaticUpdates": false        
          }
        },
        ...
    

    令人难以置信的工具Resource Explorer in Azure Portal 显示给定资源的当前配置。如您所见,EnableAutomaticUpdates 设置为 false。

    {
        "properties": {
            "vmId": "10400cdd-26be-4be4-99d8-2d5c22d96911",
            "hardwareProfile": {
                "vmSize": "Standard_D2"
            },
            "storageProfile": {
                "imageReference": {
                    "publisher": "MicrosoftWindowsServer",
                    "offer": "WindowsServer",
                    "sku": "2012-R2-Datacenter",
                    "version": "latest"
                },
                "osDisk": {
                    "osType": "Windows",
                    "name": "osdisk",
                    "createOption": "FromImage",
                    "vhd": {
                        "uri": "this_is_not_for_public_use"
                    },
                    "caching": "ReadWrite"
                },
                "dataDisks": []
            },
            "osProfile": {
                "computerName": "this_is_not_for_public_use",
                "adminUsername": "this_is_not_for_public_use",
                "windowsConfiguration": {
                    "provisionVMAgent": true,
                    "enableAutomaticUpdates": false
                },
                "secrets": []
            },
            "networkProfile": {
                "networkInterfaces": [
                    {
                        "id": "this_is_not_for_public_use/providers/Microsoft.Network/networkInterfaces/ComputeNode15-Nic"
                    }
                ]
            },
            "provisioningState": "Creating"
        },
        "id": "this_is_not_for_public_use/providers/Microsoft.Compute/virtualMachines/this_is_not_for_public_use",
        "name": "this_is_not_for_public_use",
        "type": "Microsoft.Compute/virtualMachines",
        "location": "westeurope",
        "tags": {
            "displayName": "VirtualMachine"
        }
    }
    

    我更改了模板以使用资源组的位置 - 在大多数情况下这是一个有用的选项。感谢 Martyn C 提供的提示和宝贵的反馈,将我推向了正确的方向。

    【讨论】:

    • 啊,我完全错过了,对不起!很高兴你把它整理好了?
    【解决方案2】:

    查看上面的错误消息,您将位置传递为“西欧”,而它应该是“西欧”。区域名称应全部小写。

    您可以使用 JSON 模板中的以下行来使用资源组的位置,"location": "[resourceGroup().location]",这将是更好的做法。

    【讨论】:

    • 根据github.com/Azure/azure-resource-manager-schemas/blob/master/…,使用“西欧”作为位置字符串是有效的
    • 不适用于location 属性。我刚刚从门户网站导出的模板,都说northeuropewesteurope。您的链接引用了不同的参数。
    • 这些部署运行了几个月。但可能是您的模板引用了另一个模式。请注意第一行引用schema.management.azure.com/schemas/2015-01-01/…。您的 ARM 模板有什么不同吗?
    • 您是否将它们作为部署模板参数传递?我正在使用最新的架构(实际上它是一个尚未公开的预览架构)。你能试试我的建议看看它是否有效吗?还要检查错误消息中实际列出的受支持版本... 支持的 api 版本是 '2015-05-01-preview, 2015-06-15, 2016-03-30'。
    • 我现在更改了模板,它总是使用 "location": "[resourceGroup().location]" 以减少所需参数的数量。
    猜你喜欢
    • 1970-01-01
    • 2020-06-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-30
    • 2016-08-05
    相关资源
    最近更新 更多