テンプレート名
ACS-ECS-RepairImage - イメージの修復
テンプレートの説明
イメージチェックの結果に基づき、イメージをオフラインで修復します。イメージチェックの詳細については、「イメージチェックの概要」をご参照ください。修復中、Alibaba Cloud Linux イメージから Elastic Compute Service (ECS) インスタンスが作成されます。修復対象イメージのスナップショットを取得し、そのスナップショットから作成したディスクを ECS インスタンスにアタッチします。データディスクをオフラインで修復し、修復後のデータディスクから新しいイメージを作成します。ソースイメージが Ubuntu 22.04 64-bit などのパブリックイメージの場合、生成されるイメージは ubuntu_64-bit のようなカスタムイメージとなります。
テンプレートタイプ
自動
所有者
Alibaba Cloud
入力パラメーター
|
パラメーター |
説明 |
タイプ |
必須 |
デフォルト値 |
制限 |
|
zoneId |
vSwitch が配置されているゾーン。 |
文字列 |
はい |
||
|
repairImageId |
修復対象イメージの ID。 |
文字列 |
はい |
||
|
baseImageId |
ベースイメージ |
文字列 |
はい |
||
|
instanceType |
ECS インスタンスのインスタンスタイプ。 |
文字列 |
はい |
||
|
securityGroupId |
セキュリティグループ ID。 |
文字列 |
はい |
||
|
vSwitchId |
vSwitch の ID。 |
文字列 |
はい |
||
|
regionId |
リージョン ID。 |
文字列 |
いいえ |
{{ ACS::RegionId }} |
|
|
systemDiskCategory |
システムディスクのカテゴリ。 |
文字列 |
いいえ |
cloud_essd |
|
|
repairItems |
修復対象の項目。 |
リスト |
いいえ |
['assist', 'cloudinit', 'virtio', 'nvme', 'fstab', 'grub', 'dhcp', 'growpart'] |
出力パラメーター
|
パラメーター |
説明 |
タイプ |
|
imageId |
修復後に生成されたイメージの ID。 |
文字列 |
テンプレートの実行に必要な権限ポリシー
{
"Version": "1",
"Statement": [
{
"Action": [
"ecs:CreateImage",
"ecs:CreateSnapshot",
"ecs:DeleteInstance",
"ecs:DeleteSnapshot",
"ecs:DescribeDisks",
"ecs:DescribeImages",
"ecs:DescribeInstances",
"ecs:DescribeInvocationResults",
"ecs:DescribeInvocations",
"ecs:DescribeSnapshots",
"ecs:InvokeCommand",
"ecs:RebootInstance",
"ecs:RunCommand",
"ecs:RunInstances"
],
"Resource": "*",
"Effect": "Allow"
}
]
}
詳細
詳細については、GitHub の「ACS-ECS-RepairImage.yml」をご参照ください。
テンプレートの内容
FormatVersion: OOS-2019-06-01
Description:
zh-cn: 该模板用于根据镜像检查结果离线修复镜像。关于镜像检查的更多信息,请参见 https://www.alibabacloud.com/help/ecs/user-guide/overview-18。修复过程中,会从一个 Alibaba Cloud Linux 镜像创建一个修复实例。然后,从待修复镜像的快照创建一个磁盘,并挂载到该修复实例上。数据盘被离线修复后,会从修复后的数据盘创建一个新镜像。限制:如果源镜像是公共镜像 (例如 Ubuntu 22.04 64-bit) ,修复后的镜像将是自定义镜像 (例如 ubuntu_64-bit) 。
en: This template is used to repair an image offline based on the results of an image check. For more information about image check, see https://www.alibabacloud.com/help/ecs/user-guide/overview-18. In the repair process, a repair instance is created from an Alibaba Cloud Linux image. Then, a disk is created from a snapshot of the image and attached to the repair instance. After the data disk is repaired offline, a new image is created from the repaired data disk.
name-en: ACS-ECS-RepairImage
name-zh-cn: 修复镜像
categories:
- image_manage
Parameters:
regionId:
Type: String
Label:
en: Region ID
zh-cn: 地域ID
AssociationProperty: RegionId
Default: '{{ ACS::RegionId }}'
zoneId:
Type: String
Label:
en: vSwitch Zone
zh-cn: vSwitch 可用区
AssociationProperty: ALIYUN::ECS::ZoneId
AssociationPropertyMetadata:
RegionId: regionId
repairImageId:
Type: String
Label:
en: ID of Image to Be Repaired
zh-cn: 待修复镜像ID
AssociationProperty: ALIYUN::ECS::Image::ImageId
AssociationPropertyMetadata:
RegionId: regionId
SupportedImageOwnerAlias:
- self
OSType: linux
baseImageId:
Type: String
Label:
en: Base Image
zh-cn: 基础镜像
Description:
en: '<font color=''red''>The base image is used to create the repair instance. Select a base image that has the same architecture as the target image. For example, if the custom image to be repaired is an x86_64 image, select an aliyun_3_x64 image.</font>'
zh-cn: '<font color=''red''>基础镜像用于创建修复实例。请选择与目标镜像架构相同的基础镜像。例如,如果待修复的自定义镜像是x86_64镜像,请选择aliyun_3_x64镜像。</font>'
AllowedValues:
- aliyun_3_x64_20G_alibase_20250629.vhd
- aliyun_3_arm64_20G_alibase_20250629.vhd
instanceType:
Label:
en: Instance Type
zh-cn: 实例规格
Type: String
AssociationProperty: ALIYUN::ECS::Instance::InstanceType
AssociationPropertyMetadata:
RegionId: regionId
ZoneId: zoneId
securityGroupId:
Label:
en: Security Group ID
zh-cn: 安全组ID
Type: String
AssociationProperty: ALIYUN::ECS::SecurityGroup::SecurityGroupId
AssociationPropertyMetadata:
RegionId: regionId
vSwitchId:
Label:
en: vSwitch ID
zh-cn: vSwitch ID
Type: String
AssociationProperty: ALIYUN::VPC::VSwitch::VSwitchId
AssociationPropertyMetadata:
RegionId: regionId
ZoneId: zoneId
Filters:
- SecurityGroupId: securityGroupId
systemDiskCategory:
Label:
en: System Disk Category
zh-cn: 系统盘类型
Type: String
AssociationProperty: ALIYUN::ECS::Disk::SystemDiskCategory
AssociationPropertyMetadata:
RegionId: regionId
InstanceType: instanceType
Default: cloud_essd
repairItems:
Label:
en: Repair Items
zh-cn: 修复项
Type: List
AllowedValues:
- all
- assist
- aegis
- growpart
- virtio
- selinux
- dhcp
- grub
- fstab
- nvme
- cloudinit
Default:
- assist
- cloudinit
- virtio
- nvme
- fstab
- grub
- dhcp
- growpart
Tasks:
- Name: checkImage
Action: ACS::CheckFor
Description:
en: Checks whether the image can be repaired.
zh-cn: 检查镜像是否可修复。
Properties:
Service: ECS
API: DescribeImages
PropertySelector: Images.Image[0].DetectionOptions.Items.Item[]? | select(.Name == "SystemImage") | .Value
DesiredValues: []
Parameters:
RegionId: '{{ regionId }}'
ImageId: '{{ repairImageId }}'
NotDesiredValues:
- Invalid
Outputs:
architecture:
Type: String
ValueSelector: Images.Image[0].Architecture
snapshotId:
Type: String
ValueSelector: Images.Image[0].DiskDeviceMappings.DiskDeviceMapping[0].SnapshotId
imageName:
Type: String
ValueSelector: Images.Image[0].ImageName
osType:
Type: String
ValueSelector: Images.Image[0].OSType
platform:
Type: String
ValueSelector: Images.Image[0].Platform
bootMode:
Type: String
ValueSelector: Images.Image[0].BootMode
- Name: checkImageArchitecture
Action: ACS::Choice
Description:
en: Checks whether the image architecture is x86_64 or arm64.
zh-cn: 检查镜像架构是否为x86_64或arm64。
Properties:
DefaultTask: ACS::END
Choices:
- When:
Fn::Or:
- Fn::Equals:
- x86_64
- '{{checkImage.architecture}}'
- Fn::Equals:
- arm64
- '{{checkImage.architecture}}'
NextTask: runInstances
- Name: runInstances
Action: ACS::ExecuteAPI
Description:
en: Creates an ECS instance.
zh-cn: 创建一台ECS实例。
Properties:
Service: ECS
API: RunInstances
Parameters:
RegionId: '{{ regionId }}'
Amount: 1
ImageId: '{{ baseImageId }}'
InstanceType: '{{ instanceType }}'
InstanceName: image_repair_please_no_delete
SecurityGroupId: '{{ securityGroupId }}'
VSwitchId: '{{ vSwitchId }}'
InternetMaxBandwidthIn: 200
InternetMaxBandwidthOut: 0
SystemDiskCategory: '{{ systemDiskCategory }}'
DataDisk:
- SnapshotId: '{{ checkImage.snapshotId }}'
DiskName: image_repair_{{ checkImage.snapshotId }}
Category: '{{ systemDiskCategory }}'
InstanceChargeType: PostPaid
Outputs:
instanceId:
Type: String
ValueSelector: InstanceIdSets.InstanceIdSet[0]
- Name: untilInstanceReady
Action: ACS::WaitFor
Description:
en: Waits until the instance is in the Running state.
zh-cn: 等待实例进入“运行中”状态。
Properties:
Service: ECS
API: DescribeInstances
PropertySelector: Instances.Instance[0].Status
DesiredValues:
- Running
NotDesiredValues: []
StopRetryValues: []
Parameters:
RegionId: '{{ regionId }}'
InstanceIds:
- '{{ runInstances.instanceId }}'
Retries: 10
DelayType: Exponential
Delay: 2
BackOff: 2
- Name: checkForCreatedDiskReady
Action: ACS::CheckFor
Description:
en: Checks whether the disk is in the In-use state.
zh-cn: 检查磁盘是否处于“使用中”状态。
OnError: stopInstances
Properties:
Service: ECS
API: DescribeDisks
Parameters:
RegionId: '{{ regionId }}'
InstanceId: '{{ runInstances.instanceId }}'
DesiredValues:
- In_use
PropertySelector: Disks.Disk[0].Status
Outputs:
diskSN:
Type: String
ValueSelector: Disks.Disk[0].SerialNumber
diskId:
Type: String
ValueSelector: Disks.Disk[0].DiskId
- Name: runCommandOpenselinux
Action: ACS::ECS::RunCommand
Description:
en: Runs a command on the instance.
zh-cn: 在实例上运行命令。
OnError: stopInstances
Properties:
regionId: '{{ regionId }}'
commandContent: sed -i s/^SELINUX=.*/SELINUX=permissive/g /etc/selinux/config
commandType: RunShellScript
instanceId: '{{ runInstances.instanceId }}'
Outputs:
invocationOutput:
Type: String
ValueSelector: invocationOutput
- Name: rebootInstance
Action: ACS::ECS::RebootInstance
Description:
en: Restarts the instance.
zh-cn: 重启实例。
OnError: stopInstances
Properties:
regionId: '{{ regionId }}'
instanceId: '{{ runInstances.instanceId }}'
- Name: runCommand
Action: ACS::ECS::InvokeCommand
Description:
en: Runs a command on the instance.
zh-cn: 在实例上运行命令。
OnError: stopInstances
Properties:
regionId: '{{ regionId }}'
commandId: ACS-ECS-ImageRepair-for-linux.sh
parameters:
Fn::Join:
- ''
- - '{"repairitems":'
- '"'
- Fn::Join:
- ' '
- '{{repairItems}}'
- '"'
- ',"disk_serial":"'
- '{{checkForCreatedDiskReady.diskSN}}'
- '"}'
instanceId: '{{ runInstances.instanceId }}'
Outputs:
invocationOutput:
Type: String
ValueSelector: invocationOutput
- Name: waitDiskFlush
Action: ACS::Sleep
Description:
en: Waits for I/O operations to be written to the disk.
zh-cn: 等待I/O操作写入磁盘。
Properties:
Duration: 1M
- Name: createSnapshot
Action: ACS::ECS::CreateSnapshot
Description:
en: Creates a snapshot of the disk.
zh-cn: 为磁盘创建快照。
OnError: deleteInstance
Properties:
regionId: '{{ regionId }}'
snapshotName: image_repair_{{ checkForCreatedDiskReady.diskId }}
diskId: '{{ checkForCreatedDiskReady.diskId }}'
retentionDays: 1
Outputs:
snapshotId:
Type: String
ValueSelector: snapshotId
- Name: createImage
Action: ACS::ExecuteAPI
Description:
en: Creates an image from the snapshot.
zh-cn: 从快照创建镜像。
OnError: deleteSnapshot
OnSuccess: deleteInstance
Properties:
Service: ECS
API: CreateImage
Parameters:
RegionId: '{{ regionId }}'
SnapshotId: '{{ createSnapshot.snapshotId }}'
ImageName:
Fn::Join:
- _
- - repaired
- '{{ checkImage.imageName }}'
- Fn::FormatUTCTime:
- '{{ACS::CurrentUTCTime}}'
- '%Y%m%d%H%M%S'
DetectionStrategy: Standard
Platform:
Fn::Select:
- '{{ checkImage.platform }}'
- Aliyun: Aliyun
Anolis: Anolis
CentOS: CentOS
Ubuntu: Ubuntu
SUSE: SUSE
Debian: Debian
OpenSUSE: OpenSUSE
Red Hat: RedHat
Kylin: Kylin
UOS: UOS
Fedora: Fedora
CentOS Stream: CentOS Stream
AlmaLinux: AlmaLinux
Rocky Linux: Rocky Linux
Customized Linux: Customized Linux
Others Linux: Others Linux
BootMode: '{{ checkImage.bootMode }}'
Architecture: '{{ checkImage.architecture }}'
Outputs:
imageId:
Type: String
ValueSelector: ImageId
- Name: deleteSnapshot
Action: ACS::ExecuteAPI
Description:
en: Releases the snapshot.
zh-cn: 释放快照。
OnError: deleteInstance
Properties:
Service: ECS
API: DeleteSnapshot
Parameters:
RegionId: '{{ regionId }}'
SnapshotId: '{{ createSnapshot.snapshotId }}'
Force: true
- Name: stopInstances
Action: ACS::Sleep
Description:
en: Waits for the instance protection to expire.
zh-cn: 等待实例保护到期。
Properties:
Duration: 1M
- Name: deleteInstance
Action: ACS::ExecuteAPI
Description:
en: Releases the ECS instance.
zh-cn: 释放ECS实例。
Properties:
Service: ECS
API: DeleteInstance
Parameters:
RegionId: '{{ regionId }}'
InstanceId: '{{ runInstances.instanceId }}'
Force: true
Outputs:
imageId:
Type: String
Value: '{{ createImage.imageId }}'
Metadata:
ALIYUN::OOS::Interface:
ParameterGroups:
- Parameters:
- regionId
- repairImageId
- baseImageId
Label:
default:
zh-cn: 选择镜像
en: Select Image
- Parameters:
- zoneId
- instanceType
- securityGroupId
- vSwitchId
- systemDiskCategory
Label:
default:
zh-cn: 实例配置
en: Instance Configuration
- Parameters:
- repairItems
Label:
default:
zh-cn: 执行命令
en: Run Command