When you create a CentOS system, you must manually configure a YUM repository to install common software on the system. A YUM repository is a collection of software packages. Different versions of CentOS require different YUM repositories. Resource Orchestration Service (ROS) allows you to automate the configuration of YUM repositories for different versions of CentOS by creating stacks based on templates that define mappings.

Step 1: Edit a template

Mappings are defined in the following template. The mappings contain the URLs of YUM repositories for multiple versions of CentOS. When you create an Elastic Compute Service (ECS) instance and initialize the system for the instance, the Fn::FindInMap function returns the URL of the YUM repository that matches the version of the image specified by InstanceImageId.

{
  "ROSTemplateFormatVersion": "2015-09-01",
  "Description": "Creates ECS Centos system instance, and set yum repo.",
  "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",
        },
      "Description": {
        "en": "<font color='blue'><b>Optional values:</b></font><br>[cloud_efficiency: <font color='green'>Efficient Cloud Disk</font>]<br>[cloud_ssd: <font color='green'>SSD Cloud Disk</font>]<br>[cloud_essd: <font color='green'>ESSD Cloud Disk</font>]<br>[cloud: <font color='green'>Cloud Disk</font>]<br>[ephemeral_ssd: <font color='green'>Local SSD Cloud Disk</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": {
        "en": "Image ID, support [centos_6,centos_7,centos_8]"
      },
      "Label": {
        "en": "Image"
      }
    },
    "InstanceType": {
      "Type": "String",
      "Description": {
        "en": "Fill in the specifications that can be used under the VSwitch availability zone;</b></font><br>general specifications: <font color='red'><b>ecs.c5.large</b></font><br>note: some zones do not support general specifications<br>see detail: <a href='https://www.alibabacloud.com/help/en/doc-detail/25378.html' target='_blank'><b><font color='blue'>Instance Specification Family</font></a></b>"
      },
      "Label": {
        "en": "Instance Type"
      },
      "AssociationProperty": "ALIYUN::ECS::Instance::InstanceType",
      "AssociationPropertyMetadata": {
        "ZoneId": "VSwitchZoneId"
      }
    },
    "InstancePassword": {
      "NoEcho": true,
      "Type": "String",
      "Description": {
        "en": "Server login password, Length 8-30, must contain three(Capital letters, lowercase letters, numbers, ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/ Special symbol in).",
        },
      "AllowedPattern": "[0-9A-Za-z\\_\\-\\&:;'<>,=%`~!@#\\(\\)\\$\\^\\*\\+\\|\\{\\}\\[\\]\\.\\?\\/]+$",
      "Label": {
        "en": "Instance Password",
        },
      "ConstraintDescription": {
        "en": "Length 8-30, must contain three(Capital letters, lowercase letters, numbers, ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/ Special symbol in).",
    },
      "MinLength": 8,
      "MaxLength": 30
    },
    "InstancePublicIP": {
      "Type": "Boolean",
      "Description": {
        "en": "Whether to assign a common IP."
      },
      "Label": {
        "en": "Allocate Public IP"
      },
      "Default": false
    },
    "VSwitchZoneId": {
      "AssociationProperty": "ALIYUN::ECS::Instance:ZoneId",
      "Type": "String",
      "Description": {
        "en": "Availability Zone ID.<br><b>note: <font color='blue'>before you make a selection, please confirm that the Availability Zone supports the specification of creating ECS resources, which is recommended to be different from other VSwitch Availability Zone</font></b>"
      },
      "Label": {
        "en": "VSwitch Availability Zone"
      }
    },
    "SystemDiskSize": {
      "Default": 40,
      "Type": "Number",
      "Description": {
        "en": "System disk size, range of values: 40-500, units: GB."
      },
      "Label": {
        "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::Replace": [
            {
              "ros-notify": {
                "Fn::GetAtt": [
                  "RosConditionHandle",
                  "CurlCli"
                ]
              }
            },
            {
              "Fn::Join": [
                "",
                [
                  "#!/bin/bash \n",
                  "yum_repo=",
                  {
                    "Fn::FindInMap": [
                      "YumMap",
                      {
                        "Ref": "InstanceImageId"
                      },
                      "YumSource"
                    ]
                  },
                  "\n",
                  "mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup\n",
                  "curl -o /etc/yum.repos.d/CentOS-Base.repo $yum_repo \n",
                  "yum clean all \n",
                  "yum makecache \n",
                  "ros-notify -d '{\"data\" : \"Install Centos success.\"}'\n"
                ]
              ]
            }
          ]
        },
        "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 a stack

  1. Log on to the ROS console.
  2. In the left-side navigation pane, click Stacks.
  3. In the upper-left corner of the page, select the region where you want to create the stack from the drop-down list.
  4. On the Stacks page, click Create Stack and select Use New Resources (Standard) from the drop-down list.
  5. In the Select Template step, select Select an Existing Template. Set Template Import Method to Enter Template Content, enter the JSON template content you edited in Step 1 into the Template Content code editor, and then click Next.
  6. In the Configure Template Parameters step, set Stack Name and the following parameters.
    Parameter Description Example
    VSwitch Availability Zone The zone ID of the resource. Qingdao Zone C
    Image The image ID of the ECS instance.

    Default value: centos_7.

    For more information, see Image overview.

    centos_7
    Instance Type The instance type of the ECS instance.

    Select a valid instance type. For more information, see Instance families.

    ecs.c5.large
    System Disk Space The system disk size of the ECS instance.

    Valid values: 40 to 500.

    Unit: GB

    40
    Allocate Public IP Specifies whether to allocate a public IP address to the ECS instance.
    • If you turn on Allocate Public IP, the system allocates a public IP address.
    • If you turn off Allocate Public IP, the system does not allocate a public IP address.
    Turn on Allocate Public IP
    Instance Password The password that is used to log on to the ECS instance. Test_12****
    System Disk Type The system disk category of the ECS instance. Valid values:
    • cloud_efficiency: ultra disk
    • cloud_ssd: standard SSD
    • cloud_essd: enhanced SSD (ESSD)
    • cloud: basic disk
    • ephemeral_ssd: local SSD

    For more information, see Cloud disks.

    cloud_efficiency
  7. Click Create.
  8. View the stack status on the Stack Information tab of the stack management page. After the stack is created, click the Outputs tab to obtain the ID of the ECS instance.
  9. Connect to the ECS instance in the ECS console to view the YUM repository.
    For more information about how to connect to an ECS instance, see Overview.

Step 3: View resources

  1. Log on to the ROS console.
  2. In the left-side navigation pane, click Stacks.
  3. On the Stacks page, click the ID of the stack that you created.
  4. On the stack management page, click the Resources tab to view resources.
    The following table describes the resources in this example.
    Resource Quantity Description Specifications
    ALIYUN::ECS::Instance 1 Creates an ECS instance.
    • A single instance of the following specifications is created:
    • InstanceType: ecs.c5.large
    • SystemDiskCategory: cloud_efficiency
    • SystemDiskSize: 40 (Unit: GB)
    • AllocatePublicIP: true