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: Create 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: 'Instance type. The instance type must be available in the zone to which the vSwitch belongs.</b></font><br>General instance type: <font color='red'><b>ecs.c5.large.</b></font><br>Note: The general instance type may not be available in specific zones.<br>For more information, see <a href=''https://www.alibabacloud.com/help/en/doc-detail/25378.html'' target=''_blank''><b><font color=''blue''>Overview of instance families</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: Zone ID.<br><b>Note:<font color='blue'>Before you specify a zone ID, check whether the specifications of the ECS instance are available in the zone. We recommend that you select a zone in which the vSwitch that you specify does not reside.</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::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 a stack
Log on to the ROS console.
In the left-side navigation pane, click Stacks.
In the top navigation bar, select the region of the stack from the region drop-down list. In this example, China (Hangzhou) is selected.
On the Stacks page, click Create Stack and select Use New Resources (Standard) from the drop-down list.
In the Select Template step, click Select an Existing Template. Set Template Import Method to Enter Template Content, enter the template content you edited in Step 1: Create a template in the Template Content code editor, and then click Next.
In the Configure Template Parameters step, configure 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 ECS instance type.
Select a valid instance type. For more information, see Overview of 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 IPV4 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 Disks.
cloud_efficiency
Click Create.
On the Stack Information tab, view the status of the stack. After the stack is created, click the Outputs tab to obtain the ID of the ECS instance.
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 Conection methods.
Step 3: View resources
Log on to the ROS console.
In the left-side navigation pane, click Stacks.
On the Stacks page, click the stack that you created in Step 1.
Click the Resources tab to view the information about resources in the stack.
The following table describes the resources in this example.
Resource
Quantity
Description
Specifications
ALIYUN::ECS::Instance
1
Creates an ECS instance.
Quantity: 1
Instance type: ecs.c5.large
System Disk Category: cloud_efficiency
System Disk Size: 40 GB
Allocate Public IP Addresses: Yes
null For more information about the resource charges, see the pricing schedule on the official website or the product pricing documentation.