Operations and Maintenance Layout Series - Update the scaling configuration mirror automatically after updating the mirror

Posted by portaloo on Sun, 29 Sep 2019 04:33:53 +0200

Scene introduction

Each time a new image is generated from the operations arrangement, the mirror inside the elastic stretch is directly replaced.

Solution

The scaling configuration source image is the public image aliyun_2_1903_64_20G_alibase_20190829.vhd.


Sign in Operations and Maintenance Layout Console .If you have never opened an OOS service before, click the Open Now button to open it with one click.OOS Operations and Maintenance Layout is a safe and free service, please be assured.


After opening, enter the operation and maintenance layout interface, click Custom Template, click the Create Template button.


Paste the following template in the Yaml column of the Create Template page.

FormatVersion: OOS-2019-06-01
Description:
  en: Updates an existing ECS image via ECS Cloud Assistant then creates an ECS image.
  zh-cn: Update an existing ECS Create a new one after mirroring ECS Mirror.
  name-en: ACS-ECS-UpdateImage
  name-zh-cn: To update ECS image
Parameters:
  targetImageName:
    Description:
      en: The name of new image.
      zh-cn: The name of the new mirror.
    Type: String
    AllowedPattern: '[A-Za-z0-9\-_]*'
    MinLength: 1
    MaxLength: 30
  sourceImageId:
    Description:
      en: The image ID for the ECS instance.
      zh-cn: Source Mirror ID. 
    Type: String
    AssociationProperty: 'ALIYUN::ECS::Image::ImageId'
  instanceType:
    Description:
      en: The instance type for the ECS instances.
      zh-cn: Instance type.
    Type: String
    AssociationProperty: 'ALIYUN::ECS::Instance::InstanceType'
  securityGroupId:
    Description:
      en: The security group ID for the ECS instances.
      zh-cn: Security Group ID. 
    Type: String
    AssociationProperty: 'ALIYUN::ECS::SecurityGroup::SecurityGroupId'
  vSwitchId:
    Description:
      en: The virtual switch ID for the ECS instances. 
      zh-cn: Switch ID. 
    Type: String
    AssociationProperty: 'ALIYUN::VPC::VSwitch::VSwitchId'
    AssociationPropertyMetadata:
      Filters:
        - SecurityGroupId: securityGroupId
  commandType:
    Description:
      en: The type of command.
      zh-cn: Cloud Assistant command type.
    Type: String
    AllowedValues:
      - RunBatScript
      - RunPowerShellScript
      - RunShellScript
    MinLength: 1
    MaxLength: 30
  commandContent:
    Description:
      en: Command content to run in ECS instance.
      zh-cn: stay ECS Cloud Assistant command executed in the instance.
    Type: String
    AssociationProperty: Code
  scalingConfigurationId:
    Description:
      en: The ID of the scaling configuration to be modified.
      zh-cn: The scaling configuration to be modified ID. 
    Type: String
  OOSAssumeRole:
    Description:
      en: The RAM role to be assumed by OOS.
      zh-cn: OOS Played RAM Role.
    Type: String
    Default: OOSServiceRole
RamRole: '{{ OOSAssumeRole }}'
Tasks:
- Name: checkNewImageName
  Action: ACS::CheckFor
  Description:
    en: Check image name is available.
    zh-cn: Check that the mirror name is available.
  Properties:
    Service: ECS
    API: DescribeImages
    Parameters:
      ImageName: '{{ targetImageName }}'
    DesiredValues:
    - 0
    PropertySelector: TotalCount
- Name: runInstances
  Action: ACS::ECS::RunInstances
  Description:
    en: Create a ECS instance with source image.
    zh-en: Create a Source Mirror ECS Example.
  Properties:
    imageId: '{{ sourceImageId }}'
    instanceType: '{{ instanceType }}'
    securityGroupId: '{{ securityGroupId }}'
    vSwitchId: '{{ vSwitchId }}'
  Outputs:
    instanceId:
      ValueSelector: instanceIds[0]
      Type: String
- Name: installCloudAssistant
  Action: ACS::ECS::InstallCloudAssistant
  Description:
    en: Install cloud assostant for ECS instance.
    zh-cn: Install Cloud Assistant for the instance.
  OnError: deleteInstance
  Properties:
    instanceId: '{{ runInstances.instanceId }}'
- Name: runCommand
  Action: ACS::ECS::RunCommand
  Description:
    en: Run cloud assostant command on ECS instance.
    zh-cn: Run the Cloud Assistant command in the instance.
  OnError: deleteInstance
  Properties:
    commandContent: '{{ commandContent }}'
    commandType: '{{ commandType }}'
    instanceId: '{{ runInstances.instanceId }}'
- Name: stopInstance
  Action: ACS::ECS::StopInstance
  Description:
    en: Stops the ECS instance.
    zh-cn: Stop it ECS Example.
  Properties:
    instanceId: '{{ runInstances.instanceId }}'
- Name: createImage
  Action: ACS::ECS::CreateImage
  Description:
    en: Create new image with the specified image name and instance ID.
    zh-cn: By specifying an instance ID And the mirror name to create a new image.
  OnError: deleteInstance
  Properties:
    imageName: '{{ targetImageName }}'
    instanceId: '{{ runInstances.instanceId }}'
  Outputs:
    imageId:
      ValueSelector: imageId
      Type: String
- Name: deleteInstance
  Action: ACS::ExecuteAPI
  Description:
    en: Deletes the ECS instance.
    zh-cn: delete ECS Example.
  Properties:
    Service: ECS
    API: DeleteInstance
    Risk: Normal
    Parameters:
      InstanceId: '{{ runInstances.instanceId }}'
      Force: true
- Name: modifyScalingConfiguration
  Action: ACS::ExecuteAPI
  Description:
    en: Modify scaling configuration.
    zh-cn: Modify the scaling configuration.
  Properties:
    Service: ESS
    API: ModifyScalingConfiguration
    Parameters:
      ScalingConfigurationId: '{{ scalingConfigurationId }}'
      ImageId: '{{ createImage.imageId }}'
Outputs:
  imageId:
    Type: String
    Value: '{{ createImage.imageId }}'

Enter a template name and click Create Template.


Find the template you just created on the Custom Template page and click Create to execute.


Select Auto Execute and click Next: Set parameters.



On the Parameter Settings page, enter the required parameters according to the parameter description, confirm and click Next: Confirm.


Click Confirm Risk and Execute after confirming that the risk is acceptable.


Check the execution details on the Execution Management page after confirming execution.


The View Scale Configuration Mirror ID was replaced with the latest mirror after successful execution.

Welcome to OOS

OOS Customer Support Pin Group: 23330931
Links to the OOS Management Console[](https://yq.aliyun.com/go/articleRenderRedirect?url=https%3A%2F%2Fhome.console.aliyun.com%2Fredirect.htm%3FproductId%3Decs%26amp%3Bpath%3Dautomation%2Fregion%2F)
/>
Links to OOS Help Documents

Series articles

Topic Articles

Ali Cloud Heavy Release Cloud Automation Tool-Operations and Maintenance Organization OOS

Best Practices

Permissions to play the Transport Maintenance Layout Service: Assume Role+Pass Role

Scene Series

Operations Maintenance Layout Scene Series - Update ECS Mirrors
Operations and Maintenance Layout Scene Series - -- Automatically type TAG for ECS instances
Operations Maintenance Layout Scene Series - Copying files from instances to OSS
Operations and Maintenance Layout Scene Series - Add Instances to SLS Machine Group
Operations Maintenance Layout Scene Series - Detect MFA Functional Status
Ali Cloud Operation and Maintenance New Function: One-Click Batch Cloning ECS
Operations and Maintenance Layout Scene Series - Daily statistics of the running status of multiple Region instances
Operations and Maintenance Scene Series - -- How to Use jq
Operations and Maintenance Layout Scene Series - Run commands on machines in batches

Topics: Operation & Maintenance VPC