全部产品
云市场

嵌套ACS::Template

更新时间:2019-07-15 15:05:40

用途

嵌套动作(ACS::Template)可以调用其他的模板作为子模板进行嵌套执行。利用该动作,您可以将一个复杂的模板进行模块化分解,拆分成多个子模板进行调用,也可以将常见的运维操作定义成一个可复用的子模板。另外云产品动作是OOS提供的常见类型云产品操作模版,您通过嵌套云产品动作可更便捷地进行嵌套调用,

语法

  • 通用格式(适用于所有可被嵌套模版)
    • YAML
      1. Tasks:
      2. - Name: callChildTemplate1
      3. Action: ACS::Template
      4. Properties:
      5. TemplateName: child_template_name # 必填,子模板名称
      6. Parameters: # 可选,子模板,根据子模板的参数提供参数。
      7. ParameterName1: value1
    • JSON(请参考YAML注释说明)
      1. {
      2. "Tasks": [
      3. {
      4. "Name": "callChildTemplate1",
      5. "Action": "ACS::Template",
      6. "Properties": {
      7. "TemplateName": "child_template_name",
      8. "Parameters": {
      9. "ParameterName1": "value1"
      10. }
      11. }
      12. }
      13. ]
      14. }
  • 简化格式(仅适用于嵌套云产品动作)
    • YAML
      1. Tasks:
      2. - Name: taskName # 必填,任务名称,如runMyInstances
      3. Action: CloudProductActionName1 # 必填,云产品动作名称,如ACS::ECS::RunInstances
      4. Properties:
      5. ParameterName1: value1 # 可选,根据云产品动作需要的参数进行提供,如ImageId。
    • JSON(请参考YAML注释说明)
      1. {
      2. "Tasks": [
      3. {
      4. "Name": "taskName",
      5. "Action": "CloudProductActionName1",
      6. "Properties": {
      7. "ParameterName1": "parameterName1"
      8. }
      9. }
      10. ]
      11. }

限制

嵌套动作有如下限制:

  • 模板不能嵌套自身。
  • 不能循环嵌套,即A嵌套B,B嵌套C,然后C嵌套A。
  • 总的嵌套层数不能超过3层。
  • 云产品动作属于一层嵌套,循环任务不属于嵌套。

示例

通过嵌套云产品动作ACS::ECS::CreateImage为ECS实例创建镜像。

  • 通用定义格式(适用于所有可被嵌套模版)
    • YAML:
    1. ---
    2. FormatVersion: OOS-2019-06-01
    3. Description: Creates a custom image.
    4. Parameters:
    5. imageName:
    6. Description: The image name.
    7. Type: String
    8. instanceId:
    9. Description: The ID of the instance.
    10. Type: String
    11. AllowedPattern: i-[A-Za-z0-9]*
    12. MinLength: 1
    13. MaxLength: 30
    14. OOSAssumeRole:
    15. Type: String
    16. Description: oos assume this role to execution task
    17. Default: OOSServiceRole
    18. RamRole: '{{OOSAssumeRole}}'
    19. Tasks:
    20. - Name: createImage
    21. Action: ACS::Template
    22. Description: Creates a custom image.
    23. Properties:
    24. TemplateName: 'ACS::ECS::CreateImage'
    25. Parameters:
    26. ImageName: '{{ imageName }}'
    27. InstanceId: '{{ instanceId }}'
    28. Outputs:
    29. imageId:
    30. Type: String
    31. ValueSelector: ImageId
    32. Outputs:
    33. imageId:
    34. Type: String
    35. Value: '{{ createImage.imageId }}'
    • JSON:
    1. {
    2. "FormatVersion": "OOS-2019-06-01",
    3. "Description": "Creates a custom image.",
    4. "Parameters": {
    5. "imageName": {
    6. "Description": "The image name.",
    7. "Type": "String"
    8. },
    9. "instanceId": {
    10. "Description": "The ID of the instance.",
    11. "Type": "String",
    12. "AllowedPattern": "i-[A-Za-z0-9]*",
    13. "MinLength": 1,
    14. "MaxLength": 30
    15. },
    16. "OOSAssumeRole": {
    17. "Type": "String",
    18. "Description": "oos assume this role to execution task",
    19. "Default": "OOSServiceRole"
    20. }
    21. },
    22. "RamRole": "{{OOSAssumeRole}}",
    23. "Tasks": [
    24. {
    25. "Name": "createImage",
    26. "Action": "ACS::Template",
    27. "Description": "Creates a custom image.",
    28. "Properties": {
    29. "TemplateName": "ACS::ECS::CreateImage",
    30. "Parameters": {
    31. "ImageName": "{{ imageName }}",
    32. "InstanceId": "{{ instanceId }}"
    33. }
    34. },
    35. "Outputs": {
    36. "imageId": {
    37. "Type": "String",
    38. "ValueSelector": "ImageId"
    39. }
    40. }
    41. }
    42. ],
    43. "Outputs": {
    44. "imageId": {
    45. "Type": "String",
    46. "Value": "{{ createImage.imageId }}"
    47. }
    48. }
    49. }

  • 简化定义格式(仅适用于云产品动作)
    • YAML:
    1. ---
    2. FormatVersion: OOS-2019-06-01
    3. Description: Creates a new Image from existing ECS Instance.
    4. Parameters:
    5. InstanceId:
    6. Description: the Instance Type for the new instances
    7. Type: String
    8. ImageName:
    9. Description: name of the new image
    10. Type: String
    11. OOSAssumeRole:
    12. Type: String
    13. Description: oos assume this role to execution task
    14. Default: OOSServiceRole
    15. RamRole: "{{OOSAssumeRole}}"
    16. Tasks:
    17. - Name: createImage
    18. Action: ACS::ECS::CreateImage
    19. Properties:
    20. ImageName: "{{ ImageName }}"
    21. InstanceId: "{{ InstanceId }}"
    22. Outputs:
    23. ImageId:
    24. ValueSelector: ImageId
    25. Type: String
    26. Outputs:
    27. ImageId:
    28. Type: String
    29. Value: "{{ createImage.ImageId }}"
    • JSON:
    1. {
    2. "FormatVersion": "OOS-2019-06-01",
    3. "Description": "Creates a new Image from existing ECS Instance.",
    4. "Parameters": {
    5. "InstanceId": {
    6. "Description": "the Instance Type for the new instances",
    7. "Type": "String"
    8. },
    9. "ImageName": {
    10. "Description": "name of the new image",
    11. "Type": "String"
    12. },
    13. "OOSAssumeRole": {
    14. "Type": "String",
    15. "Description": "oos assume this role to execution task",
    16. "Default": "OOSServiceRole"
    17. }
    18. },
    19. "RamRole": "{{OOSAssumeRole}}",
    20. "Tasks": [
    21. {
    22. "Name": "createImage",
    23. "Action": "ACS::ECS::CreateImage",
    24. "Properties": {
    25. "ImageName": "{{ ImageName }}",
    26. "InstanceId": "{{ InstanceId }}"
    27. },
    28. "Outputs": {
    29. "ImageId": {
    30. "ValueSelector": "ImageId",
    31. "Type": "String"
    32. }
    33. }
    34. }
    35. ],
    36. "Outputs": {
    37. "ImageId": {
    38. "Type": "String",
    39. "Value": "{{ createImage.ImageId }}"
    40. }
    41. }
    42. }