All Products
Search
Document Center

Resource Orchestration Service:Use mappings to configure yum repositories for CentOS

Last Updated:Aug 26, 2026

Different CentOS versions require different yum repositories. Resource Orchestration Service (ROS) lets you create a stack that uses mappings to automatically configure the correct yum repository based on the CentOS version of your ECS instance.

Step 1: Create the template

The following template defines a Mappings object that maps CentOS versions to Alibaba Cloud yum repository URLs. When an ECS instance starts, the Fn::FindInMap function retrieves the yum repository URL matching the CentOS version of the specified image (InstanceImageId) and replaces the default repository.

ROSTemplateFormatVersion: '2015-09-01'
Description: Creates an ECS instance that runs CentOS and configures the yum repository.
Metadata:
  ALIYUN::ROS::Interface:
    ParameterGroups:
      - Parameters:
          - VSwitchZoneId
          - InstanceImageId
          - InstanceType
          - SystemDiskSize
          - InstancePublicIP
          - InstancePassword
          - SystemDiskCategory
        Label:
          default: ECS
    TemplateTags:
      - Creates VPC ECS instance
Parameters:
  SystemDiskCategory:
    Type: String
    Label:
      en: System Disk Type
      zh-cn: 系统盘类型
    Description:
      en: '<font color=''blue''><b>Valid values:</b></font><br>[cloud_efficiency: <font color=''green''>Ultra Disk</font>]<br>[cloud_ssd: <font color=''green''>Standard SSD</font>]<br>[cloud_essd: <font color=''green''>Enhanced SSD</font>]<br>[cloud: <font color=''green''>Basic Disk</font>]<br>[ephemeral_ssd: <font color=''green''>Local SSD</font>]'
      zh-cn: '<font color=''blue''><b>可选值:</b></font><br>[cloud_efficiency: <font color=''green''>高效云盘</font>]<br>[cloud_ssd: <font color=''green''>SSD云盘</font>]<br>[cloud_essd: <font color=''green''>ESSD云盘</font>]<br>[cloud: <font color=''green''>普通云盘</font>]<br>[ephemeral_ssd: <font color=''green''>本地SSD盘</font>]'
    AllowedValues:
      - cloud_efficiency
      - cloud_ssd
      - cloud
      - cloud_essd
      - ephemeral_ssd
    Default: cloud_ssd
  InstanceImageId:
    Type: String
    Default: centos_7
    AllowedValues:
      - centos_6
      - centos_7
      - centos_8
    Description:
      zh-cn: 镜像ID, 支持选择 [centos_6,centos_7,centos_8]
      en: 'The ID of the image. Valid values: [centos_6, centos_7, centos_8].'
    Label:
      zh-cn: 镜像
      en: Image
  InstanceType:
    Type: String
    Description:
      zh-cn: 填写VSwitch可用区下可使用的规格;<br>通用规格:<font color='red'><b>ecs.c5.large</b></font><br>注:可用区可能不支持通用规格<br>规格详见:<a href='https://www.alibabacloud.com/help/zh/doc-detail/25378.html' target='_blank'><b><font color='blue'>实例规格族</font></a></b>
      en: 'The instance type. The instance type must be available in the VSwitch''s availability zone.<br>Example of a general-purpose instance type: <font color=''red''><b>ecs.c5.large</b></font><br>Note: General-purpose instance types may not be available in all availability zones.<br>For more information, see <a href=''https://www.alibabacloud.com/help/en/doc-detail/25378.html'' target=''_blank''><b><font color=''blue''>Instance families</font></a></b>.'
    Label:
      zh-cn: 实例规格
      en: Instance Type
    AssociationProperty: ALIYUN::ECS::Instance::InstanceType
    AssociationPropertyMetadata:
      ZoneId: VSwitchZoneId
  InstancePassword:
    NoEcho: true
    Type: String
    Description:
      en: 'The logon password for the instance. The password must be 8 to 30 characters in length and contain at least three of the following character types: uppercase letters, lowercase letters, digits, and special characters. Special characters include ()`~!@#$%^&*_-+=|{}[]:;''<>,.?/.'
      zh-cn: 服务器登录密码。长度为8~30个字符,必须包含大写英文字母、小写英文字母、数字和特殊字符(`()~!@#$%^&*_-+=|{}[]:;'<>,.?/)中的三项。
    AllowedPattern: '[0-9A-Za-z\_\-\&:;''<>,=%`~!@#\(\)\$\^\*\+\|\{\}\[\]\.\?\/]+$'
    Label:
      en: Instance Password
      zh-cn: 实例密码
    ConstraintDescription:
      en: 'The password must be 8 to 30 characters in length and contain at least three of the following character types: uppercase letters, lowercase letters, digits, and special characters. Special characters include ()`~!@#$%^&*_-+=|{}[]:;''<>,.?/.'
      zh-cn: 长度为8~30个字符,必须包含大写英文字母、小写英文字母、数字和特殊字符(`()~!@#$%^&*_-+=|{}[]:;'<>,.?/)中的三项。
    MinLength: 8
    MaxLength: 30
  InstancePublicIP:
    Type: Boolean
    Description:
      zh-cn: 是否分配公共IP。
      en: Specifies whether to assign a public IP address.
    Label:
      zh-cn: 分配公网IP
      en: Allocate Public IP
    Default: false
  VSwitchZoneId:
    AssociationProperty: ALIYUN::ECS::Instance:ZoneId
    Type: String
    Description:
      zh-cn: 可用区ID。<br><b>注: <font color='blue'>选择前请确认该可用区是否支持创建ECS资源的规格,建议设置与其他交换机不同的可用区</font></b>
      en: 'The ID of the availability zone.<br><b>Note: <font color=''blue''>Before you select an availability zone, make sure that the specified instance type is available in that zone. We recommend that you select an availability zone that is different from the availability zones of other VSwitches.</font></b>'
    Label:
      zh-cn: 交换机可用区
      en: VSwitch Availability Zone
  SystemDiskSize:
    Default: 40
    Type: Number
    Description:
      zh-cn: 系统盘大小, 取值范围:40~500, 单位:GB。
      en: 'The size of the system disk. Unit: GB. Valid values: 40 to 500.'
    Label:
      zh-cn: 系统盘空间
      en: System Disk Space
Mappings:
  YumMap:
    centos_6:
      YumSource: http://mirrors.aliyun.com/repo/Centos-6.repo
    centos_7:
      YumSource: http://mirrors.aliyun.com/repo/Centos-7.repo
    centos_8:
      YumSource: http://mirrors.aliyun.com/repo/Centos-8.repo
Resources:
  RosConditionHandle:
    Type: ALIYUN::ROS::WaitConditionHandle
  RosWaitCondition:
    Type: ALIYUN::ROS::WaitCondition
    DependsOn: EcsInstance
    Properties:
      Timeout: 1800
      Count: 1
      Handle:
        Ref: RosConditionHandle
  EcsVSwitch:
    Type: ALIYUN::ECS::VSwitch
    Properties:
      VpcId:
        Ref: EcsVpc
      ZoneId:
        Ref: VSwitchZoneId
      CidrBlock: 192.168.0.0/24
  EcsInstance:
    Type: ALIYUN::ECS::Instance
    Properties:
      UserData:
        Fn::Sub:
          - |
            #!/bin/bash
            mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
            curl -o /etc/yum.repos.d/CentOS-Base.repo ${yum_repo}
            yum clean all
            yum makecache
            ${ros-notify} -d '{"data" : "Install Centos success."}'
          - ros-notify:
              Fn::GetAtt:
                - RosConditionHandle
                - CurlCli
            yum_repo:
              Fn::FindInMap:
                - YumMap
                - Ref: InstanceImageId
                - YumSource
      IoOptimized: optimized
      PrivateIpAddress: 192.168.0.1
      VpcId:
        Ref: EcsVpc
      SecurityGroupId:
        Ref: EcsSecurityGroup
      VSwitchId:
        Ref: EcsVSwitch
      ImageId:
        Ref: InstanceImageId
      AllocatePublicIP:
        Ref: InstancePublicIP
      InstanceType:
        Ref: InstanceType
      SystemDiskSize:
        Ref: SystemDiskSize
      SystemDiskCategory:
        Ref: SystemDiskCategory
      Password:
        Ref: InstancePassword
  EcsSecurityGroup:
    Type: ALIYUN::ECS::SecurityGroup
    Properties:
      VpcId:
        Ref: EcsVpc
      SecurityGroupIngress:
        - PortRange: '-1/-1'
          Priority: 1
          SourceCidrIp: 0.0.0.0/0
          IpProtocol: all
          NicType: intranet
      SecurityGroupEgress:
        - PortRange: '-1/-1'
          Priority: 1
          IpProtocol: all
          DestCidrIp: 0.0.0.0/0
          NicType: intranet
  EcsVpc:
    Type: ALIYUN::ECS::VPC
    Properties:
      CidrBlock: 192.168.0.0/16
      VpcName:
        Fn::Join:
          - '-'
          - - StackId
            - Ref: ALIYUN::StackId
Outputs:
  EcsInstanceId:
    Value:
      Fn::GetAtt:
        - EcsInstance
        - InstanceId
            

Step 2: Create the stack

  1. Log in to the ROS console.

  2. In the left-side navigation pane, click Stacks.

  3. In the top navigation bar, select the region where you want to create the stack, such as China (Hangzhou).

  4. On the Stacks page, click Create Stack. In the Specify Template section, click Select an Existing Template.

    Note
    • If you select Create Template or ROS Infrastructure Composer, you are redirected to the corresponding page.

  5. On the Select Template page, set Template Import Method to Enter Template Content, enter the YAML template from Step 1, and click Next.

  6. On the Configure Parameters page, enter a Stack Name and configure the following parameters.

    Parameter

    Description

    Example

    vSwitch Availability Zone

    The availability zone of the vSwitch.

    China North 1 Zone C

    Image

    The image ID of the ECS instance.

    Default: centos_7.

    Image overview.

    centos_7

    Instance specification

    The ECS instance type.

    Select an available type. Instance families.

    ecs.c5.large

    System Disk Space

    The system disk size.

    Valid values: 40 to 500.

    Unit: GB.

    40

    Allocate Public IP

    Specifies whether to assign a public IP address to the ECS instance.

    • Selected: assigns a public IP address.

    • Cleared: does not assign a public IP address.

    Selected

    Instance Password

    The logon password for the instance.

    Test_12****

    System Disk Type

    The system disk category. Valid values:

    • cloud_efficiency: Ultra Disk.

    • cloud_ssd: Standard SSD.

    • cloud_essd: Enhanced SSD.

    • cloud: Basic Disk.

    • ephemeral_ssd: Local SSD.

    Disks.

    cloud_efficiency

  7. Click Create.

  8. On the Stack Information tab, check the stack status. After creation, click the Output tab to get the ECS instance ID.

  9. Connect to the ECS instance and verify the yum repository.

    To connect to an ECS instance, see Connection methods.

Step 3: View resources

  1. In the left-side navigation pane, click Stacks.

  2. On the Stacks page, click the name of the target stack.

  3. Click the Resources tab to view resource information.

    The following table describes the resources created in this example.

    Resource

    Quantity

    Description

    Specifications

    ALIYUN::ECS::Instance

    1

    An ECS instance.

    • Total: 1

    • Instance type: ecs.c5.large

    • System disk category: Ultra Disk

    • System disk space: 40 GB

    • Assign public IP: Yes

    Note

    For information about resource fees, see the official pricing page or the pricing documentation of each product.