すべてのプロダクト
Search
ドキュメントセンター

CloudOps Orchestration Service:宛先インスタンスの作成と検証

最終更新日:Jan 17, 2025

テンプレート名

ACS-SMC-CreateAndVerifyInstance

今すぐ実行

テンプレートの説明

宛先インスタンスとしてインスタンスを作成し、サーバ移行センタ(SMC)で宛先インスタンスを検証するためのコマンドを実行します。

テンプレートタイプ

自動化

所有者

Alibaba Cloud

入力パラメータ

パラメータ

説明

タイプ

必須

デフォルト値

制限

zoneId

ゾーン ID です。

文字列

はい

hostName

インスタンスを作成するホストの名前です。

文字列

はい

文字列検証の正規表現: ^(?!.

imageId

インスタンスを作成元のイメージの ID です。

文字列

はい

instanceType

作成されるインスタンスのインスタンスタイプです。

文字列

はい

privateIp

作成されるインスタンスの内部 IP アドレスです。

文字列

はい

regionId

リージョン ID です。

文字列

いいえ

{{ ACS::RegionId }}

systemDiskSize

システムディスクのサイズです。

数値

いいえ

19

instancesCount

作成するインスタンスの数です。

数値

いいえ

1

isDeleteInstance

検証後にインスタンスを削除するかどうかを指定します。

ブール値

いいえ

True

commandType

インスタンスの検証に使用するクラウドアシスタントコマンドのタイプです。

文字列

いいえ

RunShellScript

commandContent

インスタンスの検証に使用するクラウドアシスタントコマンドの内容です。

文字列

いいえ

""

timeout

コマンドのタイムアウト期間です。

数値

いいえ

600

workingDir

コマンドを実行するディレクトリです。

文字列

いいえ

/root

passwordInherit

イメージにプリセットされているパスワードを使用するかどうかを指定します。

ブール値

いいえ

False

rateControl

レート制御設定です。

JSON

いいえ

{'Mode': 'Concurrency', 'MaxErrors': 0, 'Concurrency': 10}

OOSAssumeRole

CloudOps Orchestration Service (OOS) がアシュームする Resource Access Management (RAM) ロールです。

文字列

いいえ

""

出力パラメータ

パラメータ

説明

タイプ

instanceCheckResults

リスト

テンプレートを実行するために必要な権限ポリシー

{
    "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"
        }
    ]
}

参照

詳細については、GitHub の ACS-SMC-CreateAndVerifyInstance をご参照ください。

テンプレートコンテンツ

FormatVersion: OOS-2019-06-01
Description:
  en: Create and verify instance by commands
  name-en: ACS-SMC-CreateAndVerifyInstance
Parameters:
  regionId:
    Type: String
    Label:
      en: RegionId
    AssociationProperty: RegionId
    Default: '{{ ACS::RegionId }}'
  zoneId:
    Label:
      en: ZoneId
    Description:
      en: The target zone id of VSwitch to create
    AssociationProperty: 'ALIYUN::ECS::Instance::ZoneId'
    Type: String
    AssociationPropertyMetadata:
      RegionId: regionId
  hostName:
    Label:
      en: HostName
    Type: String
    AllowedPattern: '^(?!\.|\-)(?!.*\.\.|.*\-\-)(?!.*_).*(?<!\.|\-)$'
    MinLength: 2
  imageId:
    Label:
      en: ImageId
    Type: String
    AssociationProperty: 'ALIYUN::ECS::Image::ImageId'
    AssociationPropertyMetadata:
      RegionId: regionId
  instanceType:
    Label:
      en: InstanceType
    Type: String
    AssociationProperty: 'ALIYUN::ECS::Instance::InstanceType'
  privateIp:
    Label:
      en: PrivateIp
    Type: String
  systemDiskSize:
    Label:
      en: SystemDiskSize
    Type: Number
    Default: 19
    MinValue: 19
    MaxValue: 500
  instancesCount:
    Label:
      en: InstancesCount
    Type: Number
    Default: 1
    MinValue: 1
    MaxValue: 999
  isDeleteInstance:
    Label:
      en: IsDeleteInstance
    Type: Boolean
    Default: true
  commandType:
    Label:
      en: CommandType
    Type: String
    AllowedValues:
      - RunBatScript
      - RunPowerShellScript
      - RunShellScript
    Default: RunShellScript
  commandContent:
    Label:
      en: CommandContent
    Type: String
    AssociationProperty: Code
    Default: ''
  timeout:
    Label:
      en: Timeout
    Type: Number
    Default: 600
  workingDir:
    Label:
      en: WorkingDir
    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)
    Label:
      en: IsUsePasswordInherit
    Type: Boolean
    Default: false
  rateControl:
    Label:
      en: RateControl
    Type: Json
    AssociationProperty: RateControl
    Default:
      Mode: Concurrency
      MaxErrors: 0
      Concurrency: 10
  OOSAssumeRole:
    Label:
      en: OOSAssumeRole
    Type: String
    Default: ''
RamRole: '{{ OOSAssumeRole }}'
Tasks:
  - Name: describeImages
    Action: 'ACS::ExecuteAPI'
    Description:
      en: Query the image ostype by image id
    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
    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
    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
    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
    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
    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
    OnSuccess: 'ACS::END'
    Action: 'ACS::ExecuteApi'
    Properties:
      Service: ROS
      API: DeleteStack
      Parameters:
        RegionId: '{{ regionId }}'
        StackId: '{{createStack.StackId}}'
Outputs:
  instanceCheckResults:
    Type: List
    Value: '{{ doInstanceCheck.commandOutputs }}'