全部產品
Search
文件中心

CloudOps Orchestration Service:ACS-SMC-CreateAndVerifyInstance

更新時間:Sep 05, 2024

模板名稱

ACS-SMC-CreateAndVerifyInstance SMC建立並驗證目標執行個體

立即執行

模板描述

SMC建立並通過執行命令驗證目標執行個體

模板類型

自動化

所有者

Alibaba Cloud

輸入參數

參數名稱

描述

類型

是否必填

預設值

約束

zoneId

可用性區域

String

hostName

將建立執行個體的主機名稱

String

字串校正Regex : ^(?!.

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 }}'