嵌套ACS::Template
更新時(shí)間:
調(diào)用其他的模板作為子模板進(jìn)行嵌套執(zhí)行。
用途
嵌套動(dòng)作(ACS::Template)可以調(diào)用其他的模板作為子模板進(jìn)行嵌套執(zhí)行。利用該動(dòng)作,您可以將一個(gè)復(fù)雜的模板進(jìn)行模塊化分解,拆分成多個(gè)子模板進(jìn)行調(diào)用,也可以將常見(jiàn)的運(yùn)維操作定義成一個(gè)可復(fù)用的子模板。另外云產(chǎn)品動(dòng)作是OOS提供的常見(jiàn)類型云產(chǎn)品操作模板,您通過(guò)嵌套云產(chǎn)品動(dòng)作可更便捷地進(jìn)行嵌套調(diào)用。
語(yǔ)法
通過(guò)模板名稱嵌套已創(chuàng)建過(guò)的模板
通用格式(適用于所有可被嵌套模板)
Tasks: - Name: callChildTemplate1 Action: ACS::Template Properties: TemplateName: child_template_name # 必填,子模板名稱 TemplateVersion: v2 # 可選,默認(rèn)取最新的版本。 Parameters: # 可選,子模板,根據(jù)子模板的參數(shù)提供參數(shù)。 ParameterName1: value1
{ "Tasks": [ { "Name": "callChildTemplate1", "Action": "ACS::Template", "Properties": { "TemplateName": "child_template_name", "TemplateVersion": "v2", "Parameters": { "ParameterName1": "value1" } } } ] }
簡(jiǎn)化格式(僅適用于嵌套云產(chǎn)品動(dòng)作)
Tasks: - Name: taskName # 必填,任務(wù)名稱,如runMyInstances Action: CloudProductActionName1 # 必填,云產(chǎn)品動(dòng)作名稱,如ACS::ECS::RunInstances Properties: ParameterName1: value1 # 可選,根據(jù)云產(chǎn)品動(dòng)作需要的參數(shù)進(jìn)行提供,如ImageId。
{ "Tasks": [ { "Name": "taskName", "Action": "CloudProductActionName1", "Properties": { "ParameterName1": "parameterName1" } } ] }
通過(guò)模板內(nèi)容嵌套未創(chuàng)建過(guò)的模板
Tasks:
- Name: callChildTemplate1
Action: ACS::Template
Properties:
TemplateContent:
FormatVersion: OOS-2019-06-01 #必填,模板的版本。
Parameters: #可選,子模板的參數(shù)。
Tasks: #可選,子模板執(zhí)行的動(dòng)作。
{
"Tasks": [
{
"Name": "callChildTemplate1",
"Action": "ACS::Template",
"Properties": {
"TemplateContent": {
"FormatVersion": "OOS-2019-06-01",
"Parameters": null,
"Tasks": null
}
}
}
]
}
限制
嵌套動(dòng)作有如下限制:
模板不能嵌套自身。
不能循環(huán)嵌套,即A嵌套B,B嵌套C,然后C嵌套A。
總的嵌套層數(shù)不能超過(guò)3層。
云產(chǎn)品動(dòng)作屬于一層嵌套,循環(huán)任務(wù)不屬于嵌套。
示例
通用定義格式(適用于所有可被嵌套模板)
--- 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 }}'
{ "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 }}" } } }
簡(jiǎn)化定義格式(僅適用于云產(chǎn)品動(dòng)作)
--- 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 }}"
{ "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 }}" } } }
FormatVersion: OOS-2019-06-01
Description:
name-en: DescribeInstances
name-zh-cn: 通過(guò)指定標(biāo)簽查看ECS實(shí)例
Parameters:
regionId:
Label:
en: The ID of region
zh-cn: 地域ID
Type: String
Default: '{{ ACS::RegionId }}'
Tasks:
- Name: describeInstances_out
Action: ACS::Template
Description:
en: Queries the ECS instances by specifying tag
zh-cn: 通過(guò)指定標(biāo)簽查看ECS實(shí)例
Properties:
TemplateContent:
FormatVersion: OOS-2019-06-01
Description: ''
Parameters:
regionId:
Label:
en: The ID of region
zh-cn: 地域ID
Type: String
Default: '{{ ACS::RegionId }}'
Tasks:
- Name: describeInstances_1
Action: ACS::Template
Description:
en: Queries the ECS instances by specifying tag
zh-cn: 通過(guò)指定標(biāo)簽查看ECS實(shí)例
Properties:
TemplateContent:
FormatVersion: OOS-2019-06-01
Description: ''
Parameters:
regionId:
Label:
en: The ID of region
zh-cn: 地域ID
Type: String
Default: '{{ ACS::RegionId }}'
Tasks:
- Name: describeInstances_2
Action: ACS::ExecuteAPI
Description:
en: Queries the ECS instances by specifying tag
zh-cn: 通過(guò)指定標(biāo)簽查看ECS實(shí)例
Properties:
Service: ECS
API: DescribeInstances
Parameters:
RegionId: '{{ regionId }}'
Outputs:
instanceIdss:
Type: List
ValueSelector: Instances.Instance[].InstanceId
Outputs:
instanceId1:
Type: List
Value: '{{ describeInstances_2.instanceIdss}}'
Parameters:
regionId: '{{ regionId }}'
Outputs:
instanceId2:
Type: List
ValueSelector: .instanceId1
Outputs:
instanceId1:
Type: List
Value: '{{ describeInstances_1.instanceId2 }}'
Parameters:
regionId: '{{ regionId }}'
Outputs:
instanceId2:
Type: List
ValueSelector: .instanceId1
Outputs:
instanceId4:
Type: List
Value: '{{ describeInstances_out.instanceId2}}'
{
"FormatVersion": "OOS-2019-06-01",
"Description": {
"name-en": "DescribeInstances",
"name-zh-cn": "通過(guò)指定標(biāo)簽查看ECS實(shí)例"
},
"Parameters": {
"regionId": {
"Label": {
"en": "The ID of region",
"zh-cn": "地域ID"
},
"Type": "String",
"Default": "{{ ACS::RegionId }}"
}
},
"Tasks": [
{
"Name": "describeInstances_out",
"Action": "ACS::Template",
"Description": {
"en": "Queries the ECS instances by specifying tag",
"zh-cn": "通過(guò)指定標(biāo)簽查看ECS實(shí)例"
},
"Properties": {
"TemplateContent": {
"FormatVersion": "OOS-2019-06-01",
"Description": "",
"Parameters": {
"regionId": {
"Label": {
"en": "The ID of region",
"zh-cn": "地域ID"
},
"Type": "String",
"Default": "{{ ACS::RegionId }}"
}
},
"Tasks": [
{
"Name": "describeInstances_1",
"Action": "ACS::Template",
"Description": {
"en": "Queries the ECS instances by specifying tag",
"zh-cn": "通過(guò)指定標(biāo)簽查看ECS實(shí)例"
},
"Properties": {
"TemplateContent": {
"FormatVersion": "OOS-2019-06-01",
"Description": "",
"Parameters": {
"regionId": {
"Label": {
"en": "The ID of region",
"zh-cn": "地域ID"
},
"Type": "String",
"Default": "{{ ACS::RegionId }}"
}
},
"Tasks": [
{
"Name": "describeInstances_2",
"Action": "ACS::ExecuteAPI",
"Description": {
"en": "Queries the ECS instances by specifying tag",
"zh-cn": "通過(guò)指定標(biāo)簽查看ECS實(shí)例"
},
"Properties": {
"Service": "ECS",
"API": "DescribeInstances",
"Parameters": {
"RegionId": "{{ regionId }}"
}
},
"Outputs": {
"instanceIdss": {
"Type": "List",
"ValueSelector": "Instances.Instance[].InstanceId"
}
}
}
],
"Outputs": {
"instanceId1": {
"Type": "List",
"Value": "{{ describeInstances_2.instanceIdss}}"
}
}
},
"Parameters": {
"regionId": "{{ regionId }}"
}
},
"Outputs": {
"instanceId2": {
"Type": "List",
"ValueSelector": ".instanceId1"
}
}
}
],
"Outputs": {
"instanceId1": {
"Type": "List",
"Value": "{{ describeInstances_1.instanceId2 }}"
}
}
},
"Parameters": {
"regionId": "{{ regionId }}"
}
},
"Outputs": {
"instanceId2": {
"Type": "List",
"ValueSelector": ".instanceId1"
}
}
}
],
"Outputs": {
"instanceId4": {
"Type": "List",
"Value": "{{ describeInstances_out.instanceId2}}"
}
}
}
文檔內(nèi)容是否對(duì)您有幫助?