模板名称
ACS-SMC-CreateAndVerifyInstance SMC创建并验证目标实例
模板描述
SMC创建并通过执行命令验证目标实例
模板类型
自动化
所有者
Alibaba Cloud
输入参数
参数名称 | 描述 | 类型 | 是否必填 | 默认值 | 约束 |
zoneId | 可用区 | String | 是 | ||
hostName | 将创建实例的主机名 | String | 是 | 字符串校验正则表达式 : ^(?!. | |
imageId | 将创建实例的镜像ID | String | 是 | ||
instanceType | 将创建实例的规格 | String | 是 | ||
privateIp | 将创建实例的内网IP | String | 是 | ||
regionId | 地域ID | String | 否 | {{ ACS::RegionId }} | |
systemDiskSize | 系统盘大小 | Number | 否 | 19 | |
instancesCount | 将创建实例的数量 | Number | 否 | 1 | |
isDeleteInstance | 检查实例完成后是否删除实例 | Boolean | 否 | True | |
commandType | 实例自定义检查云助手命令类型 | String | 否 | RunShellScript | |
commandContent | 实例自定义检查预云助手命令内容 | String | 否 | "" | |
timeout | 执行脚本的超时时间 | Number | 否 | 600 | |
workingDir | 在实例中运行命令的目录 | String | 否 | /root | |
passwordInherit | 是否使用镜像预设的密码 | Boolean | 否 | False | |
rateControl | 任务执行的并发比率 | Json | 否 | {'Mode': 'Concurrency', 'MaxErrors': 0, 'Concurrency': 10} | |
OOSAssumeRole | OOS扮演的RAM角色 | String | 否 | "" |
输出参数
参数名称 | 描述 | 类型 |
instanceCheckResults | List |
执行此模板需要的权限策略
{
"Version": "1",
"Statement": [
{
"Action": [
"ecs:DeleteInstance",
"ecs:DeleteSecurityGroup",
"ecs:DescribeCloudAssistantStatus",
"ecs:DescribeImages",
"ecs:DescribeInstances",
"ecs:DescribeInvocationResults",
"ecs:DescribeInvocations",
"ecs:InstallCloudAssistant",
"ecs:RebootInstance",
"ecs:RunCommand"
],
"Resource": "*",
"Effect": "Allow"
},
{
"Action": [
"ros:CreateStack",
"ros:DeleteStack",
"ros:GetStack"
],
"Resource": "*",
"Effect": "Allow"
},
{
"Action": [
"vpc:DeleteVSwitch",
"vpc:DeleteVpc",
"vpc:DescribeVSwitches",
"vpc:DescribeVpcs"
],
"Resource": "*",
"Effect": "Allow"
}
]
}
详情
ACS-SMC-CreateAndVerifyInstance详情
模板内容
FormatVersion: OOS-2019-06-01
Description:
en: Create and verify instance by commands
zh-cn: SMC创建并通过执行命令验证目标实例
name-en: ACS-SMC-CreateAndVerifyInstance
name-zh-cn: SMC创建并验证目标实例
Parameters:
regionId:
Type: String
Label:
en: RegionId
zh-cn: 地域ID
AssociationProperty: RegionId
Default: '{{ ACS::RegionId }}'
zoneId:
Label:
en: ZoneId
zh-cn: 可用区
Description:
en: The target zone id of VSwitch to create
zh-cn: 将创建交换机的目标可用区
AssociationProperty: 'ALIYUN::ECS::Instance::ZoneId'
Type: String
AssociationPropertyMetadata:
RegionId: regionId
hostName:
Label:
en: HostName
zh-cn: 将创建实例的主机名
Type: String
AllowedPattern: '^(?!\.|\-)(?!.*\.\.|.*\-\-)(?!.*_).*(?<!\.|\-)$'
MinLength: 2
imageId:
Label:
en: ImageId
zh-cn: 将创建实例的镜像ID
Type: String
AssociationProperty: 'ALIYUN::ECS::Image::ImageId'
AssociationPropertyMetadata:
RegionId: regionId
instanceType:
Label:
en: InstanceType
zh-cn: 将创建实例的规格
Type: String
AssociationProperty: 'ALIYUN::ECS::Instance::InstanceType'
privateIp:
Label:
en: PrivateIp
zh-cn: 将创建实例的内网IP
Type: String
systemDiskSize:
Label:
en: SystemDiskSize
zh-cn: 系统盘大小
Type: Number
Default: 19
MinValue: 19
MaxValue: 500
instancesCount:
Label:
en: InstancesCount
zh-cn: 将创建实例的数量
Type: Number
Default: 1
MinValue: 1
MaxValue: 999
isDeleteInstance:
Label:
en: IsDeleteInstance
zh-cn: 检查实例完成后是否删除实例
Type: Boolean
Default: true
commandType:
Label:
en: CommandType
zh-cn: 实例自定义检查云助手命令类型
Type: String
AllowedValues:
- RunBatScript
- RunPowerShellScript
- RunShellScript
Default: RunShellScript
commandContent:
Label:
en: CommandContent
zh-cn: 实例自定义检查预云助手命令内容
Type: String
AssociationProperty: Code
Default: ''
timeout:
Label:
en: Timeout
zh-cn: 执行脚本的超时时间
Type: Number
Default: 600
workingDir:
Label:
en: WorkingDir
zh-cn: 在实例中运行命令的目录
Type: String
Default: /root
passwordInherit:
Description:
en: To use the PasswordInherit parameter, the Password parameter must be empty and you must make sure that the selected image has a password configured(default:false)
zh-cn: 使用该参数时,Password参数必须为空,同时您需要确保使用的镜像已经设置了密码,默认为false
Label:
en: IsUsePasswordInherit
zh-cn: 是否使用镜像预设的密码
Type: Boolean
Default: false
rateControl:
Label:
en: RateControl
zh-cn: 任务执行的并发比率
Type: Json
AssociationProperty: RateControl
Default:
Mode: Concurrency
MaxErrors: 0
Concurrency: 10
OOSAssumeRole:
Label:
en: OOSAssumeRole
zh-cn: OOS扮演的RAM角色
Type: String
Default: ''
RamRole: '{{ OOSAssumeRole }}'
Tasks:
- Name: describeImages
Action: 'ACS::ExecuteAPI'
Description:
en: Query the image ostype by image id
zh-cn: 查询镜像的操作系统
Properties:
Service: ECS
API: DescribeImages
Parameters:
RegionId: '{{ regionId }}'
ImageId: '{{ imageId }}'
Outputs:
osType:
ValueSelector: 'Images.Image[0].OSType'
Type: String
- Name: converConstant
Action: 'ACS::ECS::SMCConversionConstantByJqScript'
Description:
en: Automatically convert to available CidrBlock according to PrivateIp
zh-cn: 根据PrivateIp自动转换成可用的CidrBlock
Properties:
parameter: '{{ privateIp }}'
jqScript:
- '.[0] | split(".") as $item | $item | if .[0]=="10" then "10.0.0.0/8" elif .[0]=="172" then "172.16.0.0/12" elif .[0]=="192" then "192.168.0.0/16" else "" end'
- '.[0] | split(".") as $item | $item | if .[0]=="10" then "10."+.[1]+".0.0/16" elif .[0]=="172" then "172."+.[1]+"."+.[2]+".0/24" elif .[0]=="192" then "192.168."+.[2]+".0/24" else "" end'
Outputs:
vswCidrBlock:
Type: String
ValueSelector: secondValue
vpcCidrBlock:
Type: String
ValueSelector: firstValue
- Name: createStack
Action: 'ACS::ExecuteAPI'
Description:
en: Create a resource stack
zh-cn: 创建资源栈
Properties:
Service: ROS
API: CreateStack
Parameters:
RegionId: '{{ regionId }}'
StackName: 'OOS-{{ACS::ExecutionId}}'
TimeoutInMinutes: 10
DisableRollback: false
Parameters:
- ParameterKey: hostName
ParameterValue: '{{ hostName }}'
- ParameterKey: privateIp
ParameterValue: '{{ privateIp }}'
- ParameterKey: instanceType
ParameterValue: '{{ instanceType }}'
- ParameterKey: zoneId
ParameterValue: '{{ zoneId }}'
- ParameterKey: regionId
ParameterValue: '{{ regionId }}'
- ParameterKey: imageId
ParameterValue: '{{imageId}}'
- ParameterKey: executionId
ParameterValue: '{{ ACS::ExecutionId }}'
- ParameterKey: instancesCount
ParameterValue: '{{ instancesCount }}'
- ParameterKey: systemDiskSize
ParameterValue: '{{ systemDiskSize }}'
- ParameterKey: passwordInherit
ParameterValue: '{{ passwordInherit }}'
TemplateBody:
'Fn::If':
- 'Fn::Equals':
- windows
- '{{ describeImages.osType }}'
- |
{
"Description": "Create VPC ECS instance",
"Parameters": {
"imageId": {
"Type": "String"
},
"hostName": {
"Type": "String"
},
"privateIp": {
"Type": "String"
},
"instanceType": {
"Type": "String"
},
"executionId": {
"Type": "String"
},
"instancesCount": {
"Type": "String"
},
"zoneId": {
"Type": "String"
},
"regionId": {
"Type": "String"
},
"systemDiskSize": {
"Type": "Number"
},
"passwordInherit": {
"Type": "Boolean"
},
"resourcePrefix": {
"Type": "String",
"Default": "oos-generated"
}
},
"Conditions":{
"CreateSystemDiskSize":{
"Fn::Equals":[
19,
{
"Ref":"systemDiskSize"
}
]
}
},
"ROSTemplateFormatVersion": "2015-09-01",
"Outputs": {
"ecs_instance_id": {
"Value": {
"Fn::GetAtt": [
"ecs",
"InstanceIds"
]
}
}
},
"Resources": {
"vswitch": {
"Type": "ALIYUN::ECS::VSwitch",
"Properties": {
"VpcId": {
"Ref": "vpc"
},
"Description": {
"Fn::Join": [
" ",
[
"OOS execution id is",
{
"Ref": "executionId"
}
]
]
},
"ZoneId": {
"Ref": "zoneId"
},
"CidrBlock": "{{ converConstant.vswCidrBlock }}"
}
},
"sg": {
"Type": "ALIYUN::ECS::SecurityGroup",
"Properties": {
"Tags": [
{
"Key": "oos-generated",
"Value": {
"Ref": "executionId"
}
},
{
"Key": "region",
"Value": {
"Ref": "regionId"
}
}
],
"VpcId": {
"Ref": "vpc"
},
"SecurityGroupName": {
"Fn::Join": [
"-",
[
{
"Ref": "resourcePrefix"
},
"sg"
]
]
},
"SecurityGroupEgress": [
{
"PortRange": "-1/-1",
"Priority": 1,
"IpProtocol": "all",
"DestCidrIp": "0.0.0.0/0",
"NicType": "intranet"
}
],
"SecurityGroupIngress": [
{
"PortRange": "3389/3389",
"Priority": 1,
"IpProtocol": "tcp",
"SourceCidrIp": "0.0.0.0/0",
"NicType": "intranet"
}
]
}
},
"vpc": {
"Type": "ALIYUN::ECS::VPC",
"Properties": {
"CidrBlock": "{{ converConstant.vpcCidrBlock }}",
"Description": {
"Fn::Join": [
" ",
[
"OOS execution id is",
{
"Ref": "executionId"
}
]
]
},
"VpcName": {
"Fn::Join": [
"-",
[
{
"Ref": "resourcePrefix"
},
"vpc"
]
]
}
}
},
"ecs": {
"Type": "ALIYUN::ECS::InstanceGroup",
"Properties": {
"ImageId": {
"Ref": "imageId"
},
"HostName": {
"Ref": "hostName"
},
"PrivateIpAddress": {
"Ref": "privateIp"
},
"SecurityGroupId": {
"Ref": "sg"
},
"VpcId": {
"Ref": "vpc"
},
"VSwitchId": {
"Ref": "vswitch"
},
"InstanceType": {
"Ref": "instanceType"
},
"PasswordInherit": {
"Ref": "passwordInherit"
},
"SystemDiskSize": {
"Fn::If": [
"CreateSystemDiskSize",
{
"Ref": "ALIYUN::NoValue"
},
{
"Ref": "systemDiskSize"
}
]
},
"MinAmount": {
"Ref": "instancesCount"
},
"MaxAmount": {
"Ref": "instancesCount"
},
"Tags": [
{
"Key": "oos-generated",
"Value": {
"Ref": "executionId"
}
},
{
"Key": "region",
"Value": {
"Ref": "regionId"
}
}
]
}
}
},
"Metadata": {
"ALIYUN::ROS::Interface": {
"TemplateTags": [
"acs:integrate:oos:smc_create_and_verify_instance"
]
}
}
}
- |
{
"Description": "Create VPC ECS instance",
"Parameters": {
"imageId": {
"Type": "String"
},
"hostName": {
"Type": "String"
},
"privateIp": {
"Type": "String"
},
"instanceType": {
"Type": "String"
},
"passwordInherit": {
"Type": "Boolean"
},
"executionId": {
"Type": "String"
},
"instancesCount": {
"Type": "String"
},
"zoneId": {
"Type": "String"
},
"regionId": {
"Type": "String"
},
"systemDiskSize": {
"Type": "Number"
},
"resourcePrefix": {
"Type": "String",
"Default": "oos-generated"
}
},
"Conditions":{
"CreateSystemDiskSize":{
"Fn::Equals":[
19,
{
"Ref":"systemDiskSize"
}
]
}
},
"ROSTemplateFormatVersion": "2015-09-01",
"Outputs": {
"ecs_instance_id": {
"Value": {
"Fn::GetAtt": [
"ecs",
"InstanceIds"
]
}
}
},
"Resources": {
"vswitch": {
"Type": "ALIYUN::ECS::VSwitch",
"Properties": {
"VpcId": {
"Ref": "vpc"
},
"Description": {
"Fn::Join": [
" ",
[
"OOS execution id is",
{
"Ref": "executionId"
}
]
]
},
"ZoneId": {
"Ref": "zoneId"
},
"CidrBlock": "{{ converConstant.vswCidrBlock }}"
}
},
"sg": {
"Type": "ALIYUN::ECS::SecurityGroup",
"Properties": {
"Tags": [
{
"Key": "oos-generated",
"Value": {
"Ref": "executionId"
}
},
{
"Key": "region",
"Value": {
"Ref": "regionId"
}
}
],
"VpcId": {
"Ref": "vpc"
},
"SecurityGroupName": {
"Fn::Join": [
"-",
[
{
"Ref": "resourcePrefix"
},
"sg"
]
]
},
"SecurityGroupEgress": [
{
"PortRange": "-1/-1",
"Priority": 1,
"IpProtocol": "all",
"DestCidrIp": "0.0.0.0/0",
"NicType": "intranet"
}
],
"SecurityGroupIngress": [
{
"PortRange": "22/22",
"Priority": 1,
"IpProtocol": "tcp",
"SourceCidrIp": "0.0.0.0/0",
"NicType": "intranet"
}
]
}
},
"vpc": {
"Type": "ALIYUN::ECS::VPC",
"Properties": {
"CidrBlock": "{{ converConstant.vpcCidrBlock }}",
"Description": {
"Fn::Join": [
" ",
[
"OOS execution id is",
{
"Ref": "executionId"
}
]
]
},
"VpcName": {
"Fn::Join": [
"-",
[
{
"Ref": "resourcePrefix"
},
"vpc"
]
]
}
}
},
"ecs": {
"Type": "ALIYUN::ECS::InstanceGroup",
"Properties": {
"ImageId": {
"Ref": "imageId"
},
"HostName": {
"Ref": "hostName"
},
"PrivateIpAddress": {
"Ref": "privateIp"
},
"SecurityGroupId": {
"Ref": "sg"
},
"VpcId": {
"Ref": "vpc"
},
"VSwitchId": {
"Ref": "vswitch"
},
"InstanceType": {
"Ref": "instanceType"
},
"PasswordInherit": {
"Ref": "passwordInherit"
},
"SystemDiskSize": {
"Fn::If": [
"CreateSystemDiskSize",
{
"Ref": "ALIYUN::NoValue"
},
{
"Ref": "systemDiskSize"
}
]
},
"MinAmount": {
"Ref": "instancesCount"
},
"MaxAmount": {
"Ref": "instancesCount"
},
"Tags": [
{
"Key": "oos-generated",
"Value": {
"Ref": "executionId"
}
},
{
"Key": "region",
"Value": {
"Ref": "regionId"
}
}
]
}
}
},
"Metadata": {
"ALIYUN::ROS::Interface": {
"TemplateTags": [
"acs:integrate:oos:smc_create_and_verify_instance"
]
}
}
}
Outputs:
StackId:
Type: String
ValueSelector: StackId
- Name: untilStackReady
Action: 'ACS::WaitFor'
Description:
en: Wait for the stack status CREATE_COMPLETE
zh-cn: 等待资源栈至创建成功状态
OnSuccess: doInstanceCheck
OnError: queryStackStatusReason
Properties:
Service: ROS
API: GetStack
Parameters:
RegionId: '{{ regionId }}'
StackId: '{{createStack.StackId}}'
DesiredValues:
- CREATE_COMPLETE
StopRetryValues:
- CREATE_FAILED
- CHECK_FAILED
- ROLLBACK_FAILED
- ROLLBACK_COMPLETE
- CREATE_ROLLBACK_COMPLETE
PropertySelector: Status
Outputs:
instanceIds:
Type: String
ValueSelector: 'Outputs[0].OutputValue'
- Name: doInstanceCheck
Action: 'ACS::ECS::SMCVerifyInstanceByRunCommand'
OnSuccess: 'ACS::END'
OnError: deleteStack
Description:
en: Execute cloud assistant command to check Instance
zh-cn: 执行云助手命令检查实例
Properties:
regionId: '{{ regionId }}'
instanceId: '{{ ACS::TaskLoopItem }}'
isDeleteInstance: '{{ isDeleteInstance }}'
commandContent: '{{ commandContent }}'
commandType: '{{ commandType }}'
workingDir: '{{ workingDir }}'
timeout: '{{ timeout }}'
Outputs:
commandOutput:
Type: String
ValueSelector: invocationOutput
Loop:
RateControl: '{{ rateControl }}'
Items: '{{ untilStackReady.instanceIds }}'
Outputs:
commandOutputs:
AggregateType: 'Fn::ListJoin'
AggregateField: commandOutput
- Name: queryStackStatusReason
Action: 'ACS::ExecuteAPI'
Description:
en: Query the reson of failed created stack
zh-cn: 查询资源栈未创建成功的原因
OnError: deleteStack
OnSuccess: deleteStack
Properties:
Service: ROS
API: GetStack
Parameters:
RegionId: '{{ regionId }}'
StackId: '{{ createStack.StackId }}'
Outputs:
statusReason:
Type: String
ValueSelector: StatusReason
- Name: deleteStack
Description:
en: Delete the stack
zh-cn: 删除资源栈
OnSuccess: 'ACS::END'
Action: 'ACS::ExecuteApi'
Properties:
Service: ROS
API: DeleteStack
Parameters:
RegionId: '{{ regionId }}'
StackId: '{{createStack.StackId}}'
Outputs:
instanceCheckResults:
Type: List
Value: '{{ doInstanceCheck.commandOutputs }}'