如何以编程方式将更新管理部署到 Azure 资源

How to deploy Update Management to Azure resources the programmatic way

我目前正在尝试将 Azure 的更新管理解决方案设置到我已设置的资源组。我已经阅读了很多关于这个问题的文档,包括微软的: https://docs.microsoft.com/en-us/azure/automation/automation-update-management

使用 GUI 进行设置非常简单,但是我未能找到以编程方式部署它的方法。我想联系堆栈社区,看看是否有人能够部署一个使用代码库更新管理的环境,或者是否有人拥有 found/built 可用于启用更新管理器的 powershell 模块select 个虚拟机

这块手臂模板应该可以工作:

{
    "apiVersion": "2017-05-15-preview",
    "type": "Microsoft.Automation/automationAccounts/softwareUpdateConfigurations",
    "name": "automationName/softwareUpdateName",
    "location": "[resourceGroup().location]",
    "properties": {
        "updateConfiguration": {
            "operatingSystem": "Windows",
            "duration": "PT2H0M",
            "windows": {
                "excludedKbNumbers": [
                    "168934",
                    "168973"
                ],
                "includedUpdateClassifications": "Critical",
                "rebootSetting": "IfRequired"
            },
            "azureVirtualMachines": [
                "/subscriptions/5ae68d89-69a4-454f-b5ce-e443cc4e0067/resourceGroups/myresources/providers/Microsoft.Compute/virtualMachines/vm-01",
                "/subscriptions/5ae68d89-69a4-454f-b5ce-e443cc4e0067/resourceGroups/myresources/providers/Microsoft.Compute/virtualMachines/vm-02",
                "/subscriptions/5ae68d89-69a4-454f-b5ce-e443cc4e0067/resourceGroups/myresources/providers/Microsoft.Compute/virtualMachines/vm-03"
            ],
            "nonAzureComputerNames": [
                "box1.contoso.com",
                "box2.contoso.com"
            ]
        },
        "scheduleInfo": {
            "frequency": "Hour",
            "startTime": "2017-10-19T12:22:57+00:00",
            "timeZone": "America/Los_Angeles",
            "interval": 1,
            "expiryTime": "2018-11-09T11:22:57+00:00",
            "advancedSchedule": {
                "weekDays": [
                    "Monday",
                    "Thursday"
                ]
            }
        }
    }
}

您可以使用其余部分 api 了解如何构建 properties 您需要的方式。

您可以将相同的 properties json 与 invoke-webrequest 一起用作负载,例如,或 curl。

在 powershell 中与 "Azure Updates" 交互是通过 "AzureRMAutomation" cmdlet 完成的。例如,计划软件更新使用 "New-AzureRmAutomationSoftwareUpdateConfiguration" cmdlet。

https://docs.microsoft.com/en-us/powershell/module/azurerm.automation/new-azurermautomationsoftwareupdateconfiguration?view=azurermps-6.13.0

您应该能够在该目录中找到您想要执行的任何其他操作。

我偶然发现了这个网站,它没有上述信息那么有用...

https://sharepointyankee.com/2018/02/26/importing-powershell-modules-into-azure-automation/

此过程允许您从模块库下载 powershell 模块。在对 "update" 进行简单搜索后。我找到了 2 个模块 "xWindowsUpdate" 和 "PSWindowsUpdate"。这些不直接与 azure 更新管理器交互,但在功能上实现相同的结果。

如何使用 Terraform 将更新管理自动部署到 Azure(逐步):

  • 创建自动化帐户 - 资源“azurerm_automation_account”

  • 创建 Log Analytics 工作区 - 资源“azurerm_log_analytics_workspace”

  • 将之前创建的 Log Analytics 与自动化帐户相关联 - 资源“azurerm_log_analytics_linked_service

  • 创建 Log Analytics 解决方案“更新”- 资源“azurerm_log_analytics_solution” with

     plan {
     publisher = "Microsoft"
     product   = "OMSGallery/Updates" }
    
  • 使用 ARM 模板 Terraform 资源创建更新计划 - 资源“azurerm_resource_group_template_deployment” - 4c74356b41[= 中显示的示例代码48=] 以上评论

  • 为要自动更新并添加到更新管理的虚拟机添加 Microsoft Monitoring Agent 扩展,将它们与早期的日志分析工作区连接 - 资源“azurerm_virtual_machine_extension”