ALIYUN::ROS::Sleep类型用于延迟其他资源的创建、删除、更新和回滚等操作。
语法
{
"Type": "ALIYUN::ROS::Sleep",
"Properties": {
"DeleteDuration": Number,
"UpdateRollbackDuration": Number,
"UpdateDuration": Number,
"CreateDuration": Number,
"Triggers": Map
}
}
属性
属性名称 | 类型 | 必须 | 允许更新 | 描述 | 约束 |
---|
属性名称 | 类型 | 必须 | 允许更新 | 描述 | 约束 |
---|---|---|---|---|---|
DeleteDuration | Number | 否 | 是 | 删除资源前等待的时长。 | 取值范围:0~1800。 单位:秒。 |
UpdateRollbackDuration | Number | 否 | 是 | 资源更新回滚前等待的时长。 | 仅当资源栈状态为回滚中且Triggers参数发生变化时触发。 取值范围:0~1800。 单位:秒。 |
UpdateDuration | Number | 否 | 是 | 资源更新前等待的时长。 | 仅当资源栈状态为更新中且Triggers参数发生变化时触发。 取值范围:0~1800。 单位:秒。 |
CreateDuration | Number | 否 | 否 | 创建资源前等待的时长。 | 取值范围:0~1800。 单位:秒。 |
Triggers | Map | 否 | 是 | 资源更新等待和更新回滚等待的触发器。 | 在资源栈更新或回滚时,只有更新了Triggers参数,才会触发UpdateDuration和UpdateRollbackDuration。 |
返回值
Fn::GetAtt
无
示例
本示例中定义的资源如下:
- 一个专有网络实例(VPC)
- 一个交换机(vSwitch)
- 一个安全组(SecurityGroup)
- 一个自定义延迟时间(Sleep)
- 两个ECS实例(CenterServer和OtherServer)
本示例创建了VPC网络下的ECS实例,具体如下:
- CenterServer中有自定义脚本需要部署Nginx服务,将CenterServer中的公钥发送到OtherServer,能够使CenterServer免密登录到OtherServer,OtherServer中的脚本会访问CenterServer中的服务。
- 将CreateDuration指定为60秒,等待CenterServer内部应用部署完成,以便OtherServer成功访问CenterServer中的服务。说明虽然CenterServer实例创建成功,但是内部的应用需要时间安装和启动,因此需要指定等待时间。
YAML
格式
ROSTemplateFormatVersion: '2015-09-01'
Parameters:
ZoneId:
Type: String
Label: Availability Zone
AssociationProperty: ALIYUN::ECS::Instance::ZoneId
Description: VSwitch available Zone Id,
CreateDuration:
Type: Number
Description: The number of seconds to wait before resource creation.
MinValue: 0
MaxValue: 1800
Default: 60
InstanceType:
Type: String
AssociationProperty: ALIYUN::ECS::Instance::InstanceType
Label:
en: Instance Type
zh-cn: 实例类型
Description: Fill in specifications that can be used under the VSwitch availability zone.
AssociationPropertyMetadata:
ZoneId: ${ZoneId}
SystemDiskCategory:
Type: String
AssociationProperty: ALIYUN::ECS::Disk::SystemDiskCategory
AssociationPropertyMetadata:
ZoneId: ${ZoneId}
InstanceType: ${InstanceType}
Label: System Disk Category
InstancePassword:
NoEcho: true
Type: String
Description: Server login password, Length 8-30, must contain three(Capital letters, lowercase letters, numbers.
Label: Instance Password
MinLength: 8
MaxLength: 30
Resources:
VPC:
Type: ALIYUN::ECS::VPC
Properties:
CidrBlock: 10.0.0.0/16
VSwitch:
Type: ALIYUN::ECS::VSwitch
Properties:
VpcId:
Ref: VPC
ZoneId:
Ref: ZoneId
CidrBlock: 10.0.1.0/24
SecurityGroup:
Type: ALIYUN::ECS::SecurityGroup
Properties:
VpcId:
Ref: VPC
SecurityGroupIngress:
- Priority: 1
PortRange: 80/80
NicType: intranet
SourceCidrIp: 0.0.0.0/0
IpProtocol: tcp
- Priority: 1
PortRange: 22/22
NicType: intranet
SourceCidrIp: 100.104.0.0/16
IpProtocol: tcp
WaitConditionHandle:
Type: ALIYUN::ROS::WaitConditionHandle
CenterServer:
Type: ALIYUN::ECS::InstanceGroup
Properties:
InstanceName: ControlServer
ImageId: centos_7.9
VpcId:
Ref: VPC
SecurityGroupId:
Ref: SecurityGroup
VSwitchId:
Ref: VSwitch
InstanceType:
Ref: InstanceType
Password:
Ref: InstancePassword
MaxAmount: 1
AllocatePublicIP: false
SystemDiskSize: '40'
InstanceChargeType: PostPaid
SystemDiskCategory:
Ref: SystemDiskCategory
UserData:
Fn::Replace:
- ros-notify:
Fn::GetAtt:
- WaitConditionHandle
- CurlCli
- Fn::Join:
- |+
- - '#!/bin/sh'
- ssh-keygen -t rsa -P '' -f ~/.ssh/id_rsa
- cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
- chmod 0600 ~/.ssh/authorized_keys
- pub_key=`cat /root/.ssh/id_rsa.pub`
- 'ros-notify -d "{\"status\" : \"SUCCESS\",\"id\" : \"ssh_pub_key\", \"data\" : \"$pub_key\"}" '
- yum install -y nginx
- mkdir -p /data/nginx
- echo "Hello World! This is service client ecs." > /data/nginx/index.html
- 'echo ''server {'' >> /etc/nginx/conf.d/server.conf '
- 'echo ''listen 80;'' >> /etc/nginx/conf.d/server.conf '
- 'echo ''server_name _;'' >> /etc/nginx/conf.d/server.conf '
- 'echo ''index index.html;'' >> /etc/nginx/conf.d/server.conf '
- 'echo ''root /data/nginx;'' >> /etc/nginx/conf.d/server.conf '
- 'echo ''}'' >> /etc/nginx/conf.d/server.conf '
- systemctl stop nginx
- systemctl start nginx
- systemctl enable nginx
WaitCondition:
Type: ALIYUN::ROS::WaitCondition
Properties:
Count: 1
Handle:
Ref: WaitConditionHandle
Timeout: 1800
Sleep:
Type: ALIYUN::ROS::Sleep
DependsOn: WaitCondition
Properties:
CreateDuration:
Ref: CreateDuration
OtherServer:
Type: ALIYUN::ECS::InstanceGroup
DependsOn: Sleep
Properties:
InstanceName: OtherServer
ImageId: centos_7.9
VpcId:
Ref: VPC
SecurityGroupId:
Ref: SecurityGroup
VSwitchId:
Ref: VSwitch
InstanceType:
Ref: InstanceType
Password:
Ref: InstancePassword
MaxAmount: 1
AllocatePublicIP: false
SystemDiskSize: 40
InstanceChargeType: PostPaid
SystemDiskCategory:
Ref: SystemDiskCategory
UserData:
Fn::Join:
- ''
- - |
#!/bin/sh
- ssh_pub_key='
- Fn::GetAtt:
- WaitCondition
- Data
- |
'
- |
yum install -y jq
- |
pub_key=`echo "$ssh_pub_key" | jq '.ssh_pub_key' | xargs echo `
- |
echo "$pub_key" > /root/.ssh/authorized_keys
- |
chmod 600 /root/.ssh/authorized_keys
- 'curl '
- Fn::Select:
- '0'
- Fn::GetAtt:
- CenterServer
- PrivateIps
- |
:80
JSON
格式
{
"ROSTemplateFormatVersion": "2015-09-01",
"Parameters": {
"ZoneId": {
"Type": "String",
"Label": "Availability Zone",
"AssociationProperty": "ALIYUN::ECS::Instance::ZoneId",
"Description": "VSwitch available Zone Id,"
},
"CreateDuration": {
"Type": "Number",
"Description": "The number of seconds to wait before resource creation.",
"MinValue": 0,
"MaxValue": 1800,
"Default": 60
},
"InstanceType": {
"Type": "String",
"AssociationProperty": "ALIYUN::ECS::Instance::InstanceType",
"Label": {
"en": "Instance Type",
"zh-cn": "实例类型"
},
"Description": "Fill in specifications that can be used under the VSwitch availability zone.",
"AssociationPropertyMetadata": {
"ZoneId": "${ZoneId}"
}
},
"SystemDiskCategory": {
"Type": "String",
"AssociationProperty": "ALIYUN::ECS::Disk::SystemDiskCategory",
"AssociationPropertyMetadata": {
"ZoneId": "${ZoneId}",
"InstanceType": "${InstanceType}"
},
"Label": "System Disk Category"
},
"InstancePassword": {
"NoEcho": true,
"Type": "String",
"Description": "Server login password, Length 8-30, must contain three(Capital letters, lowercase letters, numbers.",
"Label": "Instance Password",
"MinLength": 8,
"MaxLength": 30
}
},
"Resources": {
"VPC": {
"Type": "ALIYUN::ECS::VPC",
"Properties": {
"CidrBlock": "10.0.0.0/16"
}
},
"VSwitch": {
"Type": "ALIYUN::ECS::VSwitch",
"Properties": {
"VpcId": {
"Ref": "VPC"
},
"ZoneId": {
"Ref": "ZoneId"
},
"CidrBlock": "10.0.1.0/24"
}
},
"SecurityGroup": {
"Type": "ALIYUN::ECS::SecurityGroup",
"Properties": {
"VpcId": {
"Ref": "VPC"
},
"SecurityGroupIngress": [
{
"Priority": 1,
"PortRange": "80/80",
"NicType": "intranet",
"SourceCidrIp": "0.0.0.0/0",
"IpProtocol": "tcp"
},
{
"Priority": 1,
"PortRange": "22/22",
"NicType": "intranet",
"SourceCidrIp": "100.104.0.0/16",
"IpProtocol": "tcp"
}
]
}
},
"WaitConditionHandle": {
"Type": "ALIYUN::ROS::WaitConditionHandle"
},
"CenterServer": {
"Type": "ALIYUN::ECS::InstanceGroup",
"Properties": {
"InstanceName": "ControlServer",
"ImageId": "centos_7.9",
"VpcId": {
"Ref": "VPC"
},
"SecurityGroupId": {
"Ref": "SecurityGroup"
},
"VSwitchId": {
"Ref": "VSwitch"
},
"InstanceType": {
"Ref": "InstanceType"
},
"Password": {
"Ref": "InstancePassword"
},
"MaxAmount": 1,
"AllocatePublicIP": false,
"SystemDiskSize": "40",
"InstanceChargeType": "PostPaid",
"SystemDiskCategory": {
"Ref": "SystemDiskCategory"
},
"UserData": {
"Fn::Replace": [
{
"ros-notify": {
"Fn::GetAtt": [
"WaitConditionHandle",
"CurlCli"
]
}
},
{
"Fn::Join": [
"\n",
[
"#!/bin/sh",
"ssh-keygen -t rsa -P '' -f ~/.ssh/id_rsa",
"cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys",
"chmod 0600 ~/.ssh/authorized_keys",
"pub_key=`cat /root/.ssh/id_rsa.pub`",
"ros-notify -d \"{\\\"status\\\" : \\\"SUCCESS\\\",\\\"id\\\" : \\\"ssh_pub_key\\\", \\\"data\\\" : \\\"$pub_key\\\"}\" ",
"yum install -y nginx",
"mkdir -p /data/nginx",
"echo \"Hello World! This is service client ecs.\" > /data/nginx/index.html",
"echo 'server {' >> /etc/nginx/conf.d/server.conf ",
"echo 'listen 80;' >> /etc/nginx/conf.d/server.conf ",
"echo 'server_name _;' >> /etc/nginx/conf.d/server.conf ",
"echo 'index index.html;' >> /etc/nginx/conf.d/server.conf ",
"echo 'root /data/nginx;' >> /etc/nginx/conf.d/server.conf ",
"echo '}' >> /etc/nginx/conf.d/server.conf ",
"systemctl stop nginx",
"systemctl start nginx",
"systemctl enable nginx"
]
]
}
]
}
}
},
"WaitCondition": {
"Type": "ALIYUN::ROS::WaitCondition",
"Properties": {
"Count": 1,
"Handle": {
"Ref": "WaitConditionHandle"
},
"Timeout": 1800
}
},
"Sleep": {
"Type": "ALIYUN::ROS::Sleep",
"DependsOn": "WaitCondition",
"Properties": {
"CreateDuration": {
"Ref": "CreateDuration"
}
}
},
"OtherServer": {
"Type": "ALIYUN::ECS::InstanceGroup",
"DependsOn": "Sleep",
"Properties": {
"InstanceName": "OtherServer",
"ImageId": "centos_7.9",
"VpcId": {
"Ref": "VPC"
},
"SecurityGroupId": {
"Ref": "SecurityGroup"
},
"VSwitchId": {
"Ref": "VSwitch"
},
"InstanceType": {
"Ref": "InstanceType"
},
"Password": {
"Ref": "InstancePassword"
},
"MaxAmount": 1,
"AllocatePublicIP": false,
"SystemDiskSize": 40,
"InstanceChargeType": "PostPaid",
"SystemDiskCategory": {
"Ref": "SystemDiskCategory"
},
"UserData": {
"Fn::Join": [
"",
[
"#!/bin/sh\n",
"ssh_pub_key='",
{
"Fn::GetAtt": [
"WaitCondition",
"Data"
]
},
"'\n",
"yum install -y jq\n",
"pub_key=`echo \"$ssh_pub_key\" | jq '.ssh_pub_key' | xargs echo `\n",
"echo \"$pub_key\" > /root/.ssh/authorized_keys\n",
"chmod 600 /root/.ssh/authorized_keys\n",
"curl ",
{
"Fn::Select": [
"0",
{
"Fn::GetAtt": [
"CenterServer",
"PrivateIps"
]
}
]
},
":80\n"
]
]
}
}
}
}
}