模板名稱
ACS-ECS-UpdateImage 更新鏡像
模板描述
通過運行命令更新一個已存在的ECS鏡像後建立一個新ECS鏡像
模板類型
自動化
所有者
Alibaba Cloud
輸入參數
參數名稱 | 描述 | 類型 | 是否必填 | 預設值 | 約束 |
sourceImageId | 源鏡像ID | String | 是 | ||
instanceType | 執行個體類型 | String | 是 | ||
regionId | 地區ID | String | 否 | {{ ACS::RegionId }} | |
zoneId | 交換器可用性區域 | String | 否 | “” | |
targetImageName | 新鏡像的名稱 | String | 否 | UpdateImage_from_{{sourceImageId}}on{{ACS::ExecutionId}} | |
whetherCreateVpc | 是否建立VPC | Boolean | 否 | False | |
vpcCidrBlock | 專用網路IPv4網段 | String | 否 | 192.168.0.0/16 | |
vSwitchCidrBlock | 交換器子網網段 | String | 否 | 192.168.1.0/24 | |
securityGroupId | 安全性群組ID | String | 否 | “” | |
vSwitchId | 交換器ID | String | 否 | “” | |
internetMaxBandwidthOut | 流量公網頻寬 | Number | 否 | 0 | |
ramRoleName | 執行個體的RAM角色 | String | 否 | “” | |
systemDiskCategory | 系統硬碟的雲端硬碟種類 | String | 否 | cloud_essd | |
commandType | 雲助手命令類型 | String | 否 | RunShellScript | |
tags | 鏡像標籤 | Json | 否 | [] | |
commandContent | 在ECS執行個體中執行的雲助手命令 | String | 否 | echo hello | |
timeout | 逾時時間 | Number | 否 | 600 | |
updateType | 更新方式 | String | 否 | RunCommand | |
packageName | 要配置的軟體包名稱 | String | 否 | “” | |
packageVersion | 要配置的軟體包版本 | String | 否 | “” | |
parameters | 命令中的參數 | Json | 否 | {} | |
OOSAssumeRole | OOS扮演的RAM角色 | String | 否 | “” |
輸出參數
參數名稱 | 描述 | 類型 |
imageId | String |
執行此模板需要的權限原則
{
"Version": "1",
"Statement": [
{
"Action": [
"ecs:CreateImage",
"ecs:DeleteInstance",
"ecs:DescribeCloudAssistantStatus",
"ecs:DescribeImages",
"ecs:DescribeInstances",
"ecs:DescribeInvocationResults",
"ecs:DescribeInvocations",
"ecs:InstallCloudAssistant",
"ecs:RebootInstance",
"ecs:RunCommand",
"ecs:RunInstances",
"ecs:StopInstance"
],
"Resource": "*",
"Effect": "Allow"
},
{
"Action": [
"ros:CreateStack",
"ros:DeleteStack",
"ros:GetStack"
],
"Resource": "*",
"Effect": "Allow"
},
{
"Action": [
"oos:GetTemplate",
"oos:UpdateInstancePackageState"
],
"Resource": "*",
"Effect": "Allow"
},
{
"Action": [
"oss:GetObject"
],
"Resource": "*",
"Effect": "Allow"
}
]
}
詳情
模板內容
FormatVersion: OOS-2019-06-01
Description:
en: Updates an existing ECS image via ECS Cloud Assistant then creates an ECS image
zh-cn: 通過運行命令更新一個已存在的ECS鏡像後建立一個新ECS鏡像
name-en: Update Image
name-zh-cn: 更新鏡像
categories:
- image_manage
- application_manage
Parameters:
regionId:
Type: String
Label:
en: RegionId
zh-cn: 地區ID
AssociationProperty: RegionId
Default: '{{ ACS::RegionId }}'
zoneId:
Type: String
Label:
en: VSwitch Availability Zone
zh-cn: 交換器可用性區域
Default: ''
AssociationProperty: ALIYUN::ECS::Instance::ZoneId
AssociationPropertyMetadata:
RegionId: regionId
targetImageName:
Label:
en: TargetImageName
zh-cn: 新鏡像的名稱
Type: String
Description:
en: <p class="p">Note:</p> <ul class="ul"> <li class="li">Length is 2~128 English or Chinese characters</li> <li class="li"><font color='red'>must start with big or small letters or Chinese, not http:// and https://. </font></li> <li class="li">Can contain numbers, colons (:), underscores (_), or dashes (-). </li> </ul>
zh-cn: <p class="p">注意:</p> <ul class="ul"> <li class="li">長度為2~128個英文或中文字元</li> <li class="li"><font color='red'>必須以大小字母或中文開頭,不能以http://和https://開頭。</font></li> <li class="li">可以包含數字、半形冒號(:)、底線(_)或者短劃線(-)。</li> </ul>
Default: 'UpdateImage_from_{{sourceImageId}}_on_{{ACS::ExecutionId}}'
sourceImageId:
Label:
en: SourceImageId
zh-cn: 源鏡像ID
Type: String
AssociationProperty: 'ALIYUN::ECS::Image::ImageId'
AssociationPropertyMetadata:
RegionId: regionId
ImageOwnerAlias:
- self
instanceType:
Label:
en: InstanceType
zh-cn: 執行個體類型
Type: String
AssociationProperty: 'ALIYUN::ECS::Instance::InstanceType'
AssociationPropertyMetadata:
RegionId: regionId
ZoneId: zoneId
whetherCreateVpc:
Type: Boolean
Label:
en: WhetherCreateVpc
zh-cn: 是否建立VPC
Default: false
vpcCidrBlock:
Type: String
Label:
en: VPC CIDR IPv4 Block
zh-cn: 專用網路IPv4網段
Description:
zh-cn: VPC的ip位址區段範圍,<br>您可以使用以下的ip位址區段或其子網:<br><font color='green'>[10.0.0.0/8]</font><br><font color='green'>[172.16.0.0/12]</font><br><font color='green'>[192.168.0.0/16]</font>
en: 'The ip address range of the VPC in the CidrBlock form; <br>You can use the following ip address ranges and their subnets: <br><font color=''green''>[10.0.0.0/8]</font><br><font color=''green''>[172.16.0.0/12]</font><br><font color=''green''>[192.168.0.0/16]</font>'
Default: 192.168.0.0/16
AssociationProperty: ALIYUN::VPC::VPC::CidrBlock
AssociationPropertyMetadata:
Visible:
Condition:
Fn::Equals:
- ${whetherCreateVpc}
- true
vSwitchCidrBlock:
Type: String
Label:
en: VSwitch CIDR Block
zh-cn: 交換器子網網段
Description:
zh-cn: 必須屬於VPC的子網段
en: Must belong to the subnet segment of VPC
Default: 192.168.1.0/24
AssociationProperty: ALIYUN::VPC::VSwitch::CidrBlock
AssociationPropertyMetadata:
VpcCidrBlock: vpcCidrBlock
Visible:
Condition:
Fn::Equals:
- ${whetherCreateVpc}
- true
securityGroupId:
Label:
en: SecurityGroupId
zh-cn: 安全性群組ID
Type: String
Default: ''
AssociationProperty: 'ALIYUN::ECS::SecurityGroup::SecurityGroupId'
AssociationPropertyMetadata:
RegionId: regionId
Visible:
Condition:
Fn::Equals:
- ${whetherCreateVpc}
- false
vSwitchId:
Label:
en: VSwitchId
zh-cn: 交換器ID
Type: String
Default: ''
AssociationProperty: 'ALIYUN::VPC::VSwitch::VSwitchId'
AssociationPropertyMetadata:
RegionId: regionId
ZoneId: zoneId
Filters:
- SecurityGroupId: securityGroupId
Visible:
Condition:
Fn::Equals:
- ${whetherCreateVpc}
- false
internetMaxBandwidthOut:
Type: Number
Label:
zh-cn: 流量公網頻寬
en: Internet Max Bandwidth Out
Description:
zh-cn: 取值範圍0-100, 0為不開公網ip
en: no public ip if zero
Default: 0
MinValue: 0
MaxValue: 100
ramRoleName:
Label:
en: RamRoleName
zh-cn: 執行個體的RAM角色
Type: String
AssociationProperty: ALIYUN::ECS::RAM::Role
Default: ''
systemDiskCategory:
Label:
en: SystemDiskCategory
zh-cn: 系統硬碟的雲端硬碟種類
Type: String
AssociationProperty: ALIYUN::ECS::Disk::SystemDiskCategory
AssociationPropertyMetadata:
RegionId: regionId
InstanceType: instanceType
Default: cloud_essd
commandType:
Label:
en: CommandType
zh-cn: 雲助手命令類型
Type: String
AssociationPropertyMetadata:
LocaleKey: PricingCycle
Visible:
Condition:
Fn::Equals:
- ${updateType}
- RunCommand
AllowedValues:
- RunBatScript
- RunPowerShellScript
- RunShellScript
Default: RunShellScript
tags:
Label:
en: Tags
zh-cn: 鏡像標籤
Type: Json
AssociationProperty: Tags
AssociationPropertyMetadata:
ShowSystem: false
Default: []
commandContent:
Label:
en: CommandContent
zh-cn: 在ECS執行個體中執行的雲助手命令
Type: String
AssociationProperty: Code
AssociationPropertyMetadata:
Visible:
Condition:
Fn::Equals:
- ${updateType}
- RunCommand
Default: 'echo hello'
timeout:
Label:
en: Timeout
zh-cn: 逾時時間
Type: Number
AssociationPropertyMetadata:
Visible:
Condition:
Fn::Equals:
- ${updateType}
- RunCommand
Default: 600
updateType:
Label:
en: UpdateType
zh-cn: 更新方式
Type: String
AllowedValues:
- RunCommand
- InstallPackage
Default: RunCommand
AssociationPropertyMetadata:
ValueLabelMapping:
RunCommand:
zh-cn: 運行命令
en: RunCommand
InstallPackage:
zh-cn: 安裝軟體包
en: InstallPackage
packageName:
Label:
en: packageName
zh-cn: 要配置的軟體包名稱
Type: String
Default: ''
AssociationProperty: 'ALIYUN::OOS::Package::PackageName'
AssociationPropertyMetadata:
RegionId: regionId
Visible:
Condition:
Fn::Equals:
- ${updateType}
- InstallPackage
packageVersion:
Label:
en: packageVersion
zh-cn: 要配置的軟體包版本
Type: String
AssociationProperty: 'ALIYUN::OOS::Package::PackageVersion'
AssociationPropertyMetadata:
TemplateName: ${packageName}
Visible:
Condition:
Fn::Equals:
- ${updateType}
- InstallPackage
Default: ''
parameters:
Label:
en: Parameters
zh-cn: 命令中的參數
Type: Json
Default: {}
AssociationProperty: TemplateParameter
AssociationPropertyMetadata:
TemplateName: packageName
TemplateVersion: packageVersion
TemplateType: Package
Visible:
Condition:
Fn::Equals:
- ${updateType}
- InstallPackage
OOSAssumeRole:
Label:
en: OOSAssumeRole
zh-cn: OOS扮演的RAM角色
Type: String
Default: ''
RamRole: '{{ OOSAssumeRole }}'
Tasks:
- Name: checkNewImageName
Action: ACS::CheckFor
Description:
en: Check image name is available
zh-cn: 檢查鏡像名稱是可用的
Properties:
Service: ECS
API: DescribeImages
Parameters:
RegionId: '{{ regionId }}'
ImageName: '{{ targetImageName }}'
DesiredValues:
- 0
PropertySelector: TotalCount
- Name: createStack
Action: 'ACS::ExecuteAPI'
When:
Fn::Equals:
- '{{ whetherCreateVpc }}'
- true
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: ZoneId
ParameterValue: '{{ zoneId }}'
- ParameterKey: VpcCidrBlock
ParameterValue: '{{ vpcCidrBlock }}'
- ParameterKey: VSwitchCidrBlock
ParameterValue: '{{ vSwitchCidrBlock }}'
TemplateBody: |
ROSTemplateFormatVersion: '2015-09-01'
Parameters:
ZoneId:
Type: String
VpcCidrBlock:
Type: String
VSwitchCidrBlock:
Type: String
Resources:
EcsVpc:
Type: ALIYUN::ECS::VPC
Properties:
CidrBlock:
Ref: VpcCidrBlock
VpcName:
Ref: ALIYUN::StackName
EcsVSwitch:
Type: ALIYUN::ECS::VSwitch
Properties:
ZoneId:
Ref: ZoneId
VpcId:
Ref: EcsVpc
CidrBlock:
Ref: VSwitchCidrBlock
EcsSecurityGroup:
Type: ALIYUN::ECS::SecurityGroup
Properties:
VpcId:
Ref: EcsVpc
Outputs:
SecurityGroupId:
Value:
Ref: EcsSecurityGroup
VSwitchId:
Value:
Ref: EcsVSwitch
Outputs:
StackId:
Type: String
ValueSelector: StackId
- Name: untilStackReady
Action: 'ACS::WaitFor'
When:
Fn::Equals:
- '{{ whetherCreateVpc }}'
- true
Description:
en: Wait for the stack status CREATE_COMPLETE
zh-cn: 等待資源棧至建立成功狀態
OnError: deleteStack
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:
securityGroupId:
Type: String
ValueSelector: 'Outputs[0].OutputValue'
vSwitchId:
Type: String
ValueSelector: 'Outputs[1].OutputValue'
- Name: runInstances
Action: ACS::ECS::RunInstances
Description:
en: Create a ECS instance with source image
zh-cn: 用源鏡像建立一台ECS執行個體
OnError: deleteStack
Properties:
regionId: '{{ regionId }}'
imageId: '{{ sourceImageId }}'
instanceType: '{{ instanceType }}'
securityGroupId:
Fn::If:
- Fn::Equals:
- '{{ whetherCreateVpc }}'
- true
- '{{ untilStackReady.securityGroupId }}'
- '{{ securityGroupId }}'
vSwitchId:
Fn::If:
- Fn::Equals:
- '{{ whetherCreateVpc }}'
- true
- '{{ untilStackReady.vSwitchId }}'
- '{{ vSwitchId }}'
internetMaxBandwidthOut: '{{ internetMaxBandwidthOut }}'
ramRoleName: '{{ ramRoleName }}'
systemDiskCategory: '{{ systemDiskCategory }}'
Outputs:
instanceId:
ValueSelector: instanceIds[0]
Type: String
- Name: installCloudAssistant
Action: ACS::ECS::InstallCloudAssistant
Description:
en: Install cloud assistant for ECS instance
zh-cn: 給執行個體安裝雲助手
OnError: deleteInstance
Properties:
regionId: '{{ regionId }}'
instanceId: '{{ runInstances.instanceId }}'
- Name: runCommand
Action: ACS::ECS::RunCommand
When:
Fn::Equals:
- '{{ updateType }}'
- RunCommand
Description:
en: Run cloud assistant command on ECS instance
zh-cn: 在執行個體中運行雲助手命令
OnError: deleteInstance
Properties:
regionId: '{{ regionId }}'
commandContent: '{{ commandContent }}'
commandType: '{{ commandType }}'
instanceId: '{{ runInstances.instanceId }}'
timeout: '{{ timeout }}'
- Name: configurePackage
Action: ACS::ECS::ConfigureOOSPackageWithTemporaryURL
Description:
en: Configure Package
zh-cn: 配置軟體包
When:
Fn::Equals:
- '{{ updateType }}'
- InstallPackage
OnError: deleteInstance
Properties:
regionId: '{{ regionId }}'
instanceId: '{{ runInstances.instanceId }}'
packageName: '{{ packageName }}'
packageVersion: '{{ packageVersion }}'
parameters: '{{ parameters }}'
Outputs:
commandOutput:
Type: String
ValueSelector: .commandOutput
- Name: stopInstance
Action: ACS::ECS::StopInstance
Description:
en: Stops the ECS instance
zh-cn: 停止ECS執行個體
Properties:
regionId: '{{ regionId }}'
instanceId: '{{ runInstances.instanceId }}'
- Name: createImage
Action: ACS::ECS::CreateImage
Description:
en: Create new image with the specified image name and instance ID
zh-cn: 通過指定執行個體ID和鏡像名稱建立新的鏡像
OnError: deleteInstance
Properties:
regionId: '{{ regionId }}'
imageName: '{{ targetImageName }}'
instanceId: '{{ runInstances.instanceId }}'
tags: '{{tags}}'
Outputs:
imageId:
ValueSelector: imageId
Type: String
- Name: deleteInstance
Action: ACS::ExecuteAPI
Description:
en: Deletes the ECS instance
zh-cn: 刪除ECS執行個體
Properties:
Service: ECS
API: DeleteInstance
Risk: Normal
Parameters:
RegionId: '{{ regionId }}'
InstanceId: '{{ runInstances.instanceId }}'
Force: true
- Name: deleteStack
Action: 'ACS::ExecuteApi'
When:
Fn::Equals:
- '{{ whetherCreateVpc }}'
- true
Description:
en: Delete the stack
zh-cn: 刪除資源棧
Properties:
Service: ROS
API: DeleteStack
Parameters:
RegionId: '{{ regionId }}'
StackId: '{{ createStack.StackId }}'
Outputs:
imageId:
Type: String
Value: '{{ createImage.imageId }}'
Metadata:
ALIYUN::OOS::Interface:
ParameterGroups:
- Parameters:
- regionId
- sourceImageId
Label:
default:
zh-cn: 選擇源鏡像
en: Select Origin Image
- Parameters:
- targetImageName
- tags
Label:
default:
zh-cn: 鏡像設定
en: Image Configure
- Parameters:
- zoneId
- instanceType
- whetherCreateVpc
- vpcCidrBlock
- vSwitchCidrBlock
- securityGroupId
- vSwitchId
- internetMaxBandwidthOut
- systemDiskCategory
- ramRoleName
Label:
default:
zh-cn: 配置中轉執行個體
en: ECS Instance Configure
- Parameters:
- updateType
- packageName
- packageVersion
- parameters
- commandType
- commandContent
- timeout
Label:
default:
zh-cn: 更新鏡像配置
en: Update Image Configuration
- Parameters:
- OOSAssumeRole
Label:
default:
zh-cn: 進階選項
en: Control Options