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"
]
}
}
}
}