Use ROS to execute the default patch baseline

Updated at:

ROS resources

ALIYUN::OOS::Execution: Creates a patch fix execution.

Prerequisites

To protect your Alibaba Cloud account and cloud resources, we recommend that you do not use your Alibaba Cloud account to access the service unless necessary.

A RAM role is created and granted the required permissions.

  1. For more information about how to create a RAM role, see Create a RAM role for Alibaba Cloud services.

  2. For more information about how to grant permissions to a RAM role, see Manage permissions for a RAM role. The following table lists the policies that contain the required permissions of the RAM role you created.

    Policy

    Description

    AliyunOOSFullAccess

    Manages OOS.

    AliyunROSFullAccess

    Manages ROS.

    AliyunECSFullAccess

    Manages Elastic Compute Service (ECS).

Procedure

Step 1: Check the parameters

Go to the label-quickSetup-config-name-map page in the CloudOps Orchestration Service (OOS) console. Review the parameters in the following table against the page content and the ALIYUN::OOS::Execution resource type of Resource Orchestration Service (ROS).

Parameter

Data type

Description

OOSTemplateName

String

The OOS template name.

ResourceType

String

The resource type.

Targets

Json

The target instances to manage.

Timeout

Number

The timeout period.

CancelOnDelete

Boolean

Specifies whether to cancel incomplete executions when the resource is deleted.

Action

String

The operation to perform on the patch baseline.

TimerTrigger

Json

The execution mode of the patch baseline.

WhetherCreateSnapshot

Boolean

Specifies whether to create snapshots for the system disks.

RetentionDays

Number

The retention period of the snapshots.

RebootIfNeed

Boolean

Specifies whether to restart the instances if needed.

Step 2: Create an ROS template

After you check the parameters, create an ROS template using the Parameters, Resources, and Outputs sections.

Note

For more information about ROS templates, see Get started with template content.

  1. In the Parameters section, configure the custom parameters that you defined in the console.

    Parameters:
      RegionId:
        Required: true
        Type: String
        Label:    
          en: RegionId
        AssociationProperty: ALIYUN::ECS::RegionId::RegionDeploy
      OOSTemplateName:
        Type: String
        Label:     
          en: Template name
        Default: ACS-ECS-BulkyApplyPatchBaseline
        AssociationProperty: ALIYUN::OOS::Template::TemplateName
        AssociationPropertyMetadata:
          RegionId:
            Ref: RegionId
        Description:      
          en: ACS-ECS-BulkyApplyPatchBaseline:The template name used to execute patch operations.
        MinLength: 2
        MaxLength: 128
      Action:
        Default: install
        AssociationPropertyMetadata:
          LocaleKey: OOSPatchExecuteType
          ValueLabelMapping:
            install:           
              en: Install
            scan:         
              en: Scan
        AllowedValues:
          - install
          - scan
        Type: String
        Label:      
          en: Action
      TimerTrigger:
        AssociationProperty: ALIYUN::OOS::Component::TimerTrigger
        AssociationPropertyMetadata:
          MinuteInterval: 30
        Type: Json
        Label:
          en: TimerTrigger
      WhetherCreateSnapshot:
        Default: false
        AssociationPropertyMetadata:
          Visible:
            Condition:
              Fn::Equals:
                - ${Action}
                - install
        Type: Boolean
        Label:       
          en: WhetherCreateSnapshot
      RetentionDays:
        AssociationPropertyMetadata:
          Visible:
            Condition:
              Fn::Equals:
                - ${WhetherCreateSnapshot}
                - true
        Default: 7
        MaxValue: 65536
        MinValue: 1
        Label:     
          en: RetentionDays
        Type: Number
      RebootIfNeed:
        Default: false
        AssociationPropertyMetadata:
          Visible:
            Condition:
              Fn::Equals:
                - ${Action}
                - install
        Type: Boolean
        Label:     
          en: RebootIfNeed
      ResourceType:
        Type: String
        Label:
          en: ResourceType       
        AssociationPropertyMetadata:
          ValueLabelMapping:
            ALIYUN::ECS::Instance:          
              en: ECS instance
            ALIYUN::ECD::Desktop:          
              en: Desktop
        AllowedValues:
          - ALIYUN::ECS::Instance
          - ALIYUN::ECD::Desktop
        Default: ALIYUN::ECS::Instance
      Targets:
        AssociationProperty: Targets
        AssociationPropertyMetadata:
          ResourceType: ResourceType
          DeployedRegionId: RegionId
          Status: Running
        Type: Json
        Label:       
          en: TargetInstance
      Timeout:
        Type: Number
        Label:      
          en: Timeout
        Default: 1800
        Description:       
          en: Timeout in seconds'
      CancelOnDelete:
        Type: Boolean
        Label:      
          en: CancelOnDelete
        Default: true
        AllowedValues:
          - true
          - false
        AssociationPropertyMetadata:
          ValueLabelMapping:
            true:           
              en: true
            false:           
              en: false
    provider "alicloud" {
      region = "cn-hangzhou"
    }
    
    variable "patch_baseline_name" {
      description = "Patch baseline name"
      type        = string
    }
  2. In the Resources section, configure the parameters based on the dependencies of ROS resources.

    Resources:
      Execution:
        Type: ALIYUN::OOS::Execution
        # Create an execution depending on the patch baseline.
        DependsOn: OOSPatchBaseline
        Properties:
          TemplateName:
            Ref: OOSTemplateName
          Parameters:
            resourceType:
              Ref: ResourceType
            targets:
              Ref: Targets
            Action:
              Ref: Action
            TimerTrigger:
              Ref: TimerTrigger
            WhetherCreateSnapshot:
              Ref: WhetherCreateSnapshot
            RetentionDays:
              Ref: RetentionDays
          ResourceOptions:
            SuccessStatuses:
              - Running
              - Success
              - Queued
              - Waiting
            Timeout:
              Ref: Timeout
            CancelOnDelete:
              Ref: CancelOnDelete
    resource "alicloud_oos_patch_baseline" "baseline" {
      patch_baseline_name = var.patch_baseline_name
      operation_system    = "Windows"
      approval_rules = local.approval_rules_json
    }
    resource "alicloud_oos_default_patch_baseline" "default" {
      patch_baseline_name = alicloud_oos_patch_baseline.baseline.patch_baseline_name
    }
    resource "alicloud_oos_execution" "example" {
      template_name = "ACS-ECS-BulkyApplyPatchBaseline"
      parameters    = local.oos_parameters_json
      depends_on    = [alicloud_oos_patch_baseline.baseline,alicloud_oos_default_patch_baseline.default]
    }
  3. The Outputs section returns the information of created resources.

    Outputs:
      Execution:
        Description:
           
          en: Whether the execution is successful.
        Value:
          Fn::GetAtt:
            - Execution
            - Status
    output "patch_baseline_id" {
      value = alicloud_oos_patch_baseline.baseline.id
    }
  4. In the Metadata section, divide the parameters into groups.

    Metadata:
      ALIYUN::ROS::Interface:
        ParameterGroups:
          - Parameters:
              - PatchBaselineName
              - OperationSystem
              - Product
              - Classification
              - Severity
              - DefaultPatchBaseline
            Label:           
              en: Patch baseline
          - Parameters:
              - OOSTemplateName
              - ResourceType
              - Targets
              - Timeout
              - CancelOnDelete
              - Action
              - TimerTrigger
              - WhetherCreateSnapshot
              - RetentionDays
              - RebootIfNeed
            Label:           
              en: Execution parameters
    locals {
      approval_rules_json = <<EOF
    {
      "PatchRules": [
        {
          "EnableNonSecurity": true,
          "PatchFilterGroup": [
            {
              "Values": ["OS"],
              "Key": "PatchSet"
            },
            {
              "Values": ["Windows"],
              "Key": "ProductFamily"
            },
            {
              "Values": ["Windows 10", "Windows 7", "Windows Server 2022"],
              "Key": "Product"
            },
            {
              "Values": ["Security Updates", "Updates", "Update Rollups", "Critical Updates"],
              "Key": "Classification"
            },
            {
              "Values": ["Critical", "Important"],
              "Key": "Severity"
            }
          ],
          "ApproveAfterDays": 7,
          "ComplianceLevel": "Medium"
        }
      ]
    }
    EOF
      oos_parameters_json = <<EOF
    {
        "resourceType": "ALIYUN::ECS::Instance",
        "targets": {
            "Type": "All",
            "Parameters": {
                "regionId": "cn-hangzhou",
                "Status": "Running"
            }
        }
    }
    EOF
    }
  5. Complete sample template:

    ROSTemplateFormatVersion: "2015-09-01"
    Description:   
      en: Use ROS to schedule or execute patch baselines.
    Parameters:
      RegionId:
        Required: true
        Type: String
        Label:       
          en: RegionId
        AssociationProperty: ALIYUN::ECS::RegionId::RegionDeploy
      OOSTemplateName:
        Type: String
        Label:      
          en: Template name
        Default: ACS-ECS-BulkyApplyPatchBaseline
        AssociationProperty: ALIYUN::OOS::Template::TemplateName
        AssociationPropertyMetadata:
          RegionId:
            Ref: RegionId
        Description:       
          en: ACS-ECS-BulkyApplyPatchBaseline:The template name used to execute patch operations.
        MinLength: 2
        MaxLength: 128
      Action:
        Default: install
        AssociationPropertyMetadata:
          LocaleKey: OOSPatchExecuteType
          ValueLabelMapping:
            install:           
              en: Install
            scan:          
              en: Scan
        AllowedValues:
          - install
          - scan
        Type: String
        Label:     
          en: Action
      TimerTrigger:
        AssociationProperty: ALIYUN::OOS::Component::TimerTrigger
        AssociationPropertyMetadata:
          MinuteInterval: 30
        Type: Json
        Label:       
          en: TimerTrigger
      WhetherCreateSnapshot:
        Default: false
        AssociationPropertyMetadata:
          Visible:
            Condition:
              Fn::Equals:
                - ${Action}
                - install
        Type: Boolean
        Label:     
          en: WhetherCreateSnapshot
      RetentionDays:
        AssociationPropertyMetadata:
          Visible:
            Condition:
              Fn::Equals:
                - ${WhetherCreateSnapshot}
                - true
        Default: 7
        MaxValue: 65536
        MinValue: 1
        Label:      
          en: RetentionDays
        Type: Number
      RebootIfNeed:
        Default: false
        AssociationPropertyMetadata:
          Visible:
            Condition:
              Fn::Equals:
                - ${Action}
                - install
        Type: Boolean
        Label:       
          en: RebootIfNeed
      ResourceType:
        Type: String
        Label:
          en: ResourceType       
        AssociationPropertyMetadata:
          ValueLabelMapping:
            ALIYUN::ECS::Instance:           
              en: ECS instance
            ALIYUN::ECD::Desktop:           
              en: Desktop
        AllowedValues:
          - ALIYUN::ECS::Instance
          - ALIYUN::ECD::Desktop
        Default: ALIYUN::ECS::Instance
      Targets:
        AssociationProperty: Targets
        AssociationPropertyMetadata:
          ResourceType: ResourceType
          DeployedRegionId: RegionId
          Status: Running
        Type: Json
        Label:       
          en: TargetInstance
      Timeout:
        Type: Number
        Label:
          en: Timeout
        Default: 1800
        Description:      
          en: Timeout in seconds'
      CancelOnDelete:
        Type: Boolean
        Label:      
          en: CancelOnDelete
        Default: true
        AllowedValues:
          - true
          - false
        AssociationPropertyMetadata:
          ValueLabelMapping:
            true:          
              en: true
            false:
              en: false
    Resources:
      Execution:
        Type: ALIYUN::OOS::Execution
        Properties:
          TemplateName:
            Ref: OOSTemplateName
          Parameters:
            resourceType:
              Ref: ResourceType
            targets:
              Ref: Targets
            Action:
              Ref: Action
            TimerTrigger:
              Ref: TimerTrigger
            WhetherCreateSnapshot:
              Ref: WhetherCreateSnapshot
            RetentionDays:
              Ref: RetentionDays
          ResourceOptions:
            SuccessStatuses:
              - Running
              - Success
              - Queued
              - Waiting
            Timeout:
              Ref: Timeout
            CancelOnDelete:
              Ref: CancelOnDelete
    Outputs:
      Execution:
        Description:      
          en: Whether the execution is successful.
        Value:
          Fn::GetAtt:
            - Execution
            - Status
    Metadata:
      ALIYUN::ROS::Interface:
        ParameterGroups:
          - Parameters:
              - OOSTemplateName
              - ResourceType
              - Targets
              - Timeout
              - CancelOnDelete
              - Action
              - TimerTrigger
              - WhetherCreateSnapshot
              - RetentionDays
              - RebootIfNeed
            Label:         
              en: Execution parameters
    terraform {
      required_providers {
        alicloud = {
          source  = "aliyun/alicloud"
          version = "1.229.1"
        }
      }
    }
    provider "alicloud" {
      region = "cn-hangzhou"
    }
    
    variable "patch_baseline_name" {
      description = "Patch baseline name"
      type        = string
    }
    locals {
      approval_rules_json = <<EOF
    {
      "PatchRules": [
        {
          "EnableNonSecurity": true,
          "PatchFilterGroup": [
            {
              "Values": ["OS"],
              "Key": "PatchSet"
            },
            {
              "Values": ["Windows"],
              "Key": "ProductFamily"
            },
            {
              "Values": ["Windows 10", "Windows 7", "Windows Server 2022"],
              "Key": "Product"
            },
            {
              "Values": ["Security Updates", "Updates", "Update Rollups", "Critical Updates"],
              "Key": "Classification"
            },
            {
              "Values": ["Critical", "Important"],
              "Key": "Severity"
            }
          ],
          "ApproveAfterDays": 7,
          "ComplianceLevel": "Medium"
        }
      ]
    }
    EOF
      oos_parameters_json = <<EOF
    {
        "resourceType": "ALIYUN::ECS::Instance",
        "targets": {
            "Type": "All",
            "Parameters": {
                "regionId": "cn-hangzhou",
                "Status": "Running"
            }
        }
    }
    EOF
    }
    resource "alicloud_oos_patch_baseline" "baseline" {
      patch_baseline_name = var.patch_baseline_name
      operation_system    = "Windows"
      approval_rules = local.approval_rules_json
    }
    resource "alicloud_oos_default_patch_baseline" "default" {
      patch_baseline_name = alicloud_oos_patch_baseline.baseline.patch_baseline_name
    }
    resource "alicloud_oos_execution" "example" {
      template_name = "ACS-ECS-BulkyApplyPatchBaseline"
      parameters    = local.oos_parameters_json
      depends_on    = [alicloud_oos_patch_baseline.baseline,alicloud_oos_default_patch_baseline.default]
    }
    output "patch_baseline_id" {
      value = alicloud_oos_patch_baseline.baseline.id
    }

Step 3: Use the ROS template to create a stack

This section covers only the main steps for stack creation. For more information, see Create a stack.

  1. Log on to the ROS> Deployment> Stacks and go to the Stacks page.

  2. Click Create Stack.

  3. On the Create Stack page, copy and paste the complete sample template provided in Step 2 to the Template Content field. Then, click Next.

  4. Configure the template and resource stack, and click Next.

  5. After you complete the Compliance Precheck and Check and Confirm steps, click Create.

  6. On the Stacks page, view the created stack.

    • If the Status of the stack is Created., the stack is created.

    • If the Status of the stack is Failed, you can click Diagnostics to view the cause of the failure.

  7. Click the Resources tab, and then click the resource ID to go to the console of the resource.

References

To create a custom patch baseline, see Create and execute a patch baseline by using ROS.