Azure 更新管理 - ARM 服务配置

Azure Update Management - ARM service configuration

我将使用 ARM 模板在 Azure 中配置更新管理服务。我不想从头开始部署更新管理,我想创建更新部署并使用 ARM 安排补丁。我创建了 teml 文件和 param 文件,请看下面。我正在使用脚本来部署 json 文件,如下所示。我遇到这样的错误:New-AzureRmDeployment : 11:14:04 AM - Error: Code=InvalidTemplate; Message=Deployment template validation failed: 'The resource 'Microsoft.Automation/automationAccounts/UpdateTesting' is not defined in the template. Please see https://aka.ms/arm-template for usage details.'.

Template file:

    {
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "automationAccounts_UpdateTesting_name": {
            "type": "String"
        }
    },
    "variables": {},
    "resources": [ {
            "type": "Microsoft.Automation/automationAccounts/schedules",
            "apiVersion": "2015-10-31",
            "name": "[concat(parameters('automationAccounts_UpdateTesting_name'), '/testfromarm')]",
            "dependsOn": [
                "[resourceId('Microsoft.Automation/automationAccounts', parameters('automationAccounts_UpdateTesting_name'))]"
            ],
            "properties": {
                "startTime": "2020-03-10T10:57:00+01:00",
                "expiryTime": "2020-03-10T10:57:00+01:00",
                "frequency": "OneTime",
                "timeZone": "Europe/Warsaw"
            }
        },
        {
            "type": "Microsoft.Automation/automationAccounts/softwareUpdateConfigurations",
            "apiVersion": "2017-05-15-preview",
            "name": "[concat(parameters('automationAccounts_UpdateTesting_name'), '/testfromarm')]",
            "dependsOn": [
                "[resourceId('Microsoft.Automation/automationAccounts', parameters('automationAccounts_UpdateTesting_name'))]"
            ],
            "properties": {
                "updateConfiguration": {
                    "operatingSystem": "Windows",
                    "windows": {
                        "includedUpdateClassifications": "Critical, Security, UpdateRollup, Updates",
                        "rebootSetting": "IfRequired"
                    },
                    "targets": {
                        "azureQueries": [
                            {
                                "scope": [
                                    "/subscriptions/xxx"
                                ],
                                "tagSettings": {
                                    "tags": {
                                        "PatchGroup": [
                                            "group01"
                                        ]
                                    },
                                    "filterOperator": "All"
                                },
                                "locations": []
                            },
                            {
                                "scope": [
                                    "/subscriptions/xxx"
                                ],
                                "tagSettings": {
                                    "tags": {
                                        "PatchGroup": [
                                            "group02"
                                        ]
                                    },
                                    "filterOperator": "All"
                                },
                                "locations": []
                            }
                        ]
                    },
                    "duration": "PT2H"
                },
                "tasks": {},
                "scheduleInfo": {}
            }
        }

    ],
    "outputs": {}
}

Param file:

    {
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "automationAccounts_UpdateTesting_name": {
            "value": "UpdateTesting"
        }
    }
}

Deployment script:

    param(
    [Parameter(Mandatory=$true)]
    [string] $TemplateFilePath,
    [Parameter(Mandatory=$true)]
    [string] $TemplateParameterFilePath,
    [Parameter(Mandatory=$true)]
    [string] $DeploymentName,
    [Parameter(Mandatory=$true)]
    [string] $Location
)

$ErrorActionPreference = "Stop"
if ((Test-Path $TemplateFilePath) -and (Test-Path $TemplateParameterFilePath)) {
    New-AzureRmDeployment -Location $Location -Name $DeploymentName -TemplateFile $TemplateFilePath -TemplateParameterFile $TemplateParameterFilePath
} else {
    Write-Error "One of required files was not found"
}

我使用以下 link 创建 json 模板文件:softwareUpdateConfigurations,并使用下面提供的 ps1 脚本创建 运行 模板和参数文件:

powershell 脚本到 运行 模板:

param(
    [Parameter(Mandatory=$true)]
    [string] $ResourceGroupName,
    [Parameter(Mandatory=$true)]
    [string] $TemplateFilePath,
    [Parameter(Mandatory=$true)]
    [string] $TemplateParameterFilePath
)

if((Test-Path $TemplateFilePath) -and (Test-Path $TemplateParameterFilePath)) {
    New-AzureRmResourceGroupDeployment -ResourceGroupName $ResourceGroupName -TemplateFile $TemplateFilePath -TemplateParameterFile $TemplateParameterFilePath
} else {
    Write-Error "One of required files was not found."
}

参数文件:

{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "automationAccounts_name": {
        "value": "xxx"
        },
        "location": {
        "value": "xxx"
        },
        "scheduleName1": {
        "value": "xxx"
        }
    }
}