调用其他的模板作为子模板进行嵌套执行。
用途
嵌套动作(ACS::Template)可以调用其他的模板作为子模板进行嵌套执行。利用该动作,您可以将一个复杂的模板进行模块化分解,拆分成多个子模板进行调用,也可以将常见的运维操作定义成一个可复用的子模板。另外云产品动作是OOS提供的常见类型云产品操作模板,您通过嵌套云产品动作可更便捷地进行嵌套调用。
语法
通用格式(适用于所有可被嵌套模板)
YAML
Tasks: - Name: callChildTemplate1 Action: ACS::Template Properties: TemplateName: child_template_name # 必填,子模板名称 TemplateVersion: v2 # 可选,默认取最新的版本。 Parameters: # 可选,子模板,根据子模板的参数提供参数。 ParameterName1: value1
JSON(请参考YAML注释说明)
{ "Tasks": [ { "Name": "callChildTemplate1", "Action": "ACS::Template", "Properties": { "TemplateName": "child_template_name","TemplateVersion": "v2", "Parameters": { "ParameterName1": "value1" } } } ] }
简化格式(仅适用于嵌套云产品动作)
YAML
Tasks: - Name: taskName # 必填,任务名称,如runMyInstances Action: CloudProductActionName1 # 必填,云产品动作名称,如ACS::ECS::RunInstances Properties: ParameterName1: value1 # 可选,根据云产品动作需要的参数进行提供,如ImageId。
JSON(请参考YAML注释说明)
{ "Tasks": [ { "Name": "taskName", "Action": "CloudProductActionName1", "Properties": { "ParameterName1": "parameterName1" } } ] }
限制
嵌套动作有如下限制:
模板不能嵌套自身。
不能循环嵌套,即A嵌套B,B嵌套C,然后C嵌套A。
总的嵌套层数不能超过3层。
云产品动作属于一层嵌套,循环任务不属于嵌套。
示例
通过嵌套云产品动作ACS::ECS::CreateImage
为ECS实例创建镜像。
通用定义格式(适用于所有可被嵌套模板)
YAML
--- FormatVersion: OOS-2019-06-01 Description: Creates a custom image. Parameters: imageName: Description: The image name. Type: String instanceId: Description: The ID of the instance. Type: String AllowedPattern: i-[A-Za-z0-9]* MinLength: 1 MaxLength: 30 OOSAssumeRole: Type: String Description: oos assume this role to execution task Default: OOSServiceRole RamRole: '{{OOSAssumeRole}}' Tasks: - Name: createImage Action: ACS::Template Description: Creates a custom image. Properties: TemplateName: 'ACS::ECS::CreateImage' Parameters: ImageName: '{{ imageName }}' InstanceId: '{{ instanceId }}' Outputs: imageId: Type: String ValueSelector: ImageId Outputs: imageId: Type: String Value: '{{ createImage.imageId }}'
JSON
{ "FormatVersion": "OOS-2019-06-01", "Description": "Creates a custom image.", "Parameters": { "imageName": { "Description": "The image name.", "Type": "String" }, "instanceId": { "Description": "The ID of the instance.", "Type": "String", "AllowedPattern": "i-[A-Za-z0-9]*", "MinLength": 1, "MaxLength": 30 }, "OOSAssumeRole": { "Type": "String", "Description": "oos assume this role to execution task", "Default": "OOSServiceRole" } }, "RamRole": "{{OOSAssumeRole}}", "Tasks": [ { "Name": "createImage", "Action": "ACS::Template", "Description": "Creates a custom image.", "Properties": { "TemplateName": "ACS::ECS::CreateImage", "Parameters": { "ImageName": "{{ imageName }}", "InstanceId": "{{ instanceId }}" } }, "Outputs": { "imageId": { "Type": "String", "ValueSelector": "ImageId" } } } ], "Outputs": { "imageId": { "Type": "String", "Value": "{{ createImage.imageId }}" } } }
简化定义格式(仅适用于云产品动作)
YAML
--- FormatVersion: OOS-2019-06-01 Description: Creates a new Image from existing ECS Instance. Parameters: InstanceId: Description: the Instance Type for the new instances Type: String ImageName: Description: name of the new image Type: String OOSAssumeRole: Type: String Description: oos assume this role to execution task Default: OOSServiceRole RamRole: "{{OOSAssumeRole}}" Tasks: - Name: createImage Action: ACS::ECS::CreateImage Properties: ImageName: "{{ ImageName }}" InstanceId: "{{ InstanceId }}" Outputs: ImageId: ValueSelector: ImageId Type: String Outputs: ImageId: Type: String Value: "{{ createImage.ImageId }}"
JSON
{ "FormatVersion": "OOS-2019-06-01", "Description": "Creates a new Image from existing ECS Instance.", "Parameters": { "InstanceId": { "Description": "the Instance Type for the new instances", "Type": "String" }, "ImageName": { "Description": "name of the new image", "Type": "String" }, "OOSAssumeRole": { "Type": "String", "Description": "oos assume this role to execution task", "Default": "OOSServiceRole" } }, "RamRole": "{{OOSAssumeRole}}", "Tasks": [ { "Name": "createImage", "Action": "ACS::ECS::CreateImage", "Properties": { "ImageName": "{{ ImageName }}", "InstanceId": "{{ InstanceId }}" }, "Outputs": { "ImageId": { "ValueSelector": "ImageId", "Type": "String" } } } ], "Outputs": { "ImageId": { "Type": "String", "Value": "{{ createImage.ImageId }}" } } }
反馈
- 本页导读 (0)
文档反馈