选择目标资源ACS::SelectTargets

使用该动作,当设置参数时,批量选择资源将会非常方便。

用途

如果您在模板中使用了ACS::SelectTargets动作,并定义了包含"AssociationProperty": "Targets"的模板参数,当您创建执行来设置参数时,可轻易切换批量选取资源的方式。有手动选择资源、指定资源的标签、选择全部资源、CSV文件(包含资源ID)和指定配置清单条件几种方式,方便您快速完成资源的批量选择。

selecttargets

语法

FormatVersion: OOS-2019-06-01
Description: 'ACS::SelectTargets usage'
Parameters:
  targets:  # 参数名,用来选择资源范围。
    Type: Json  # 参数类型,固定为Json。
    AssociationProperty: Targets    # 参数关联的动作,对应ACS::SelectTargets时,固定为Targets 。
    AssociationPropertyMetadata:  # 参数要选择的资源定义。
      ResourceType: ALIYUN::ECS::Instance # 要选择的资源类型。
                    # ALIYUN::ECS::Instance  资源为ECS实例
                    # ALIYUN::ECD::Desktop 资源为ECD云桌面
                    # ALIYUN::RDS::Instance 资源为RDS实例
                    # ALIYUN::Redis::Instance 资源为REDIS实例
                    # ALIYUN::MongoDB::Instance 资源为MongoDB实例
                    # ALIYUN::ECS::ManagedInstance 资源为ECS托管实例
                    # ALIYUN::ComputeNestSupplier::Instance 资源为ComputeNestSupplier实例
Tasks:
  - Name: getInstance # 任务名称。
    Action: 'ACS::SelectTargets'  # 确定选择具体资源的动作。
    Properties:
      ResourceType: 'ALIYUN::ECS::Instance'  # 要选择的资源类型。
      Filters: # 要筛选的范围。
        - '{{ targets }}'  # 选择资源范围的参数名。
    Outputs:  # 任务输出。
      instanceIds: # 任务输出参数名。
        Type: List  # 输出参数类型。
        ValueSelector: 'Instances.Instance[].InstanceId'  # jq Selector,其筛选的对象为该资源类型的Describe OpenAPI返回结果,比如ECS实例的筛选对象则是DescribeInstances OpenAPI的返回结果。
{
  "FormatVersion": "OOS-2019-06-01",
  "Description": "ACS::SelectTargets usage",
  "Parameters": {
    "targets": {
      "Type": "Json",
      "AssociationProperty": "Targets",
      "AssociationPropertyMetadata": {
        "ResourceType": "ALIYUN::ECS::Instance"
      }
    }
  },
  "Tasks": [
    {
      "Name": "getInstance",
      "Action": "ACS::SelectTargets",
      "Properties": {
        "ResourceType": "ALIYUN::ECS::Instance",
        "Filters": [
          "{{ targets }}"
        ]
      },
      "Outputs": {
        "instanceIds": {
          "Type": "List",
          "ValueSelector": "Instances.Instance[].InstanceId"
        }
      }
    }
  ]
}

模板示例

  • 批量启动ECS实例

    FormatVersion: OOS-2019-06-01
    Description:
      en: Bulky starts the ECS instances.
      zh-cn: 批量启动ECS实例。
      name-en: ACS-ECS-BulkyStartInstances
      name-zh-cn: 批量启动ECS实例
      categories:
        - instance_manage
    Parameters:
      targets:
        Type: Json
        AssociationProperty: Targets
        AssociationPropertyMetadata:
          ResourceType: 'ALIYUN::ECS::Instance'
      rateControl:
        Description:
          en: Concurrency ratio of task execution.
          zh-cn: 任务执行的并发比率。
        Type: Json
        AssociationProperty: RateControl
        Default:
          Mode: Concurrency
          MaxErrors: 0
          Concurrency: 10
      OOSAssumeRole:
        Description:
          en: The RAM role to be assumed by OOS.
          zh-cn: OOS扮演的RAM角色。
        Type: String
        Default: OOSServiceRole
    RamRole: '{{ OOSAssumeRole }}'
    Tasks:
      - Name: getInstance
        Description:
          en: Views the ECS instances.
          zh-cn: 获取ECS实例。
        Action: 'ACS::SelectTargets'
        Properties:
          ResourceType: 'ALIYUN::ECS::Instance'
          Filters:
            - '{{ targets }}'
        Outputs:
          instanceIds:
            Type: List
            ValueSelector: 'Instances.Instance[].InstanceId'
      - Name: startInstance
        Action: 'ACS::ECS::StartInstance'
        Description:
          en: Starts the ECS instances.
          zh-cn: 启动实例。
        Properties:
          instanceId: '{{ ACS::TaskLoopItem }}'
        Loop:
          RateControl: '{{ rateControl }}'
          Items: '{{ getInstance.instanceIds }}'
    Outputs:
      instanceIds:
        Type: List
        Value: '{{ getInstance.instanceIds }}'
    {
      "FormatVersion": "OOS-2019-06-01",
      "Description": {
        "en": "Bulky starts the ECS instances.",
        "zh-cn": "批量启动ECS实例。",
        "name-en": "ACS-ECS-BulkyStartInstances",
        "name-zh-cn": "批量启动ECS实例",
        "categories": [
          "instance_manage"
        ]
      },
      "Parameters": {
        "targets": {
          "Type": "Json",
          "AssociationProperty": "Targets",
          "AssociationPropertyMetadata": {
            "ResourceType": "ALIYUN::ECS::Instance"
          }
        },
        "rateControl": {
          "Description": {
            "en": "Concurrency ratio of task execution.",
            "zh-cn": "任务执行的并发比率。"
          },
          "Type": "Json",
          "AssociationProperty": "RateControl",
          "Default": {
            "Mode": "Concurrency",
            "MaxErrors": 0,
            "Concurrency": 10
          }
        },
        "OOSAssumeRole": {
          "Description": {
            "en": "The RAM role to be assumed by OOS.",
            "zh-cn": "OOS扮演的RAM角色。"
          },
          "Type": "String",
          "Default": "OOSServiceRole"
        }
      },
      "RamRole": "{{ OOSAssumeRole }}",
      "Tasks": [
        {
          "Name": "getInstance",
          "Description": {
            "en": "Views the ECS instances.",
            "zh-cn": "获取ECS实例。"
          },
          "Action": "ACS::SelectTargets",
          "Properties": {
            "ResourceType": "ALIYUN::ECS::Instance",
            "Filters": [
              "{{ targets }}"
            ]
          },
          "Outputs": {
            "instanceIds": {
              "Type": "List",
              "ValueSelector": "Instances.Instance[].InstanceId"
            }
          }
        },
        {
          "Name": "startInstance",
          "Action": "ACS::ECS::StartInstance",
          "Description": {
            "en": "Starts the ECS instances.",
            "zh-cn": "启动实例。"
          },
          "Properties": {
            "instanceId": "{{ ACS::TaskLoopItem }}"
          },
          "Loop": {
            "RateControl": "{{ rateControl }}",
            "Items": "{{ getInstance.instanceIds }}"
          }
        }
      ],
      "Outputs": {
        "instanceIds": {
          "Type": "List",
          "Value": "{{ getInstance.instanceIds }}"
        }
      }
    }

不同ECS实例选择方式targets参数示例

  • 根据实例ID选择

    targets:
      Type: ResourceIds
      RegionId: cn-hangzhou
      ResourceIds:
        - i-******************1
        - i-******************2
        - i-******************3
    {
      "targets": {
        "Type": "ResourceIds",
        "RegionId": "cn-hangzhou",
        "ResourceIds": [
          "i-******************1",
          "i-******************2",
          "i-******************3"
        ]
      }
    }
  • 根据标签选择(最多选择1000实例,如果大于1000请使用通过标签选择ECS实例并执行命令模板

    targets:
      Type: Tags
      RegionId: cn-hangzhou
      Tags:
        - Key: key1
          Value: value1
        - Key: key2
          Value: value2
    {
      "targets": {
        "Type": "Tags",
        "RegionId": "cn-hangzhou",
        "Tags": [
          {
            "Key": "key1",
            "Value": "value1"
          },
          {
            "Key": "key2",
            "Value": "value2"
          }
        ]
      }
    }
  • 根据资源组选择

    targets:
      Type: ResourceGroup
      RegionId: cn-hangzhou
      ResourceGroupId: rg-acf*********re3y
    {
      "targets": {
        "Type": "ResourceGroup",
        "RegionId": "cn-hangzhou",
        "ResourceGroupId": "rg-acf*********re3y"
      }
    }
  • 选择所有实例

    targets:
      Type: All
      RegionId: cn-hangzhou
      Parameters:
        RegionId: cn-hangzhou
        Status: Running
        Tags:
          - Key: key1
            Value: value1
    {
      "targets": {
        "Type": "All",
        "RegionId": "cn-hangzhou",
        "Parameters": {
          "RegionId": "cn-hangzhou",
          "Status": "Running",
          "Tags": [
            {
              "Key": "key1",
              "Value": "value1"
            }
          ]
        }
      }
    }
  • 根据指定配置清单条件选择

    targets:
        Type: Inventory
        RegionId: cn-hangzhou
        InventoryFilters:
          - Name: TypeName
            Operator: Equal
            Value:
              - ACS:InstanceInformation
          - Name: ACS:InstanceInformation.Status
            Value:
              - Running
            Operator: Equal
    {
      "targets": {
        "Type": "Inventory",
        "RegionId": "cn-hangzhou",
        "InventoryFilters": [
          {
            "Name": "TypeName",
            "Operator": "Equal",
            "Value": [
              "ACS:InstanceInformation"
            ]
          },
          {
            "Name": "ACS:InstanceInformation.Status",
            "Value": [
              "Running"
            ],
            "Operator": "Equal"
          }
        ]
      }
    }

选择计算巢服务实例Targets参数示例

  • 获取计算巢服务实例模板示例

    FormatVersion: OOS-2019-06-01
    Parameters:
      RegionId:
        Type: String
        Label:
          en: RegionId
          zh-cn: 地域ID
        AssociationProperty: RegionId
        Default: '{{ ACS::RegionId }}'
      Targets:
        Type: Json
        Label:
          en: TargetInstance
          zh-cn: 目标实例
        AssociationProperty: Targets
        AssociationPropertyMetadata:
          ResourceType: ALIYUN::ComputeNestSupplier::Instance
          RegionId: RegionId
      RateControl:
        Label:
          en: RateControl
          zh-cn: 任务执行的并发比率
        Type: Json
        AssociationProperty: RateControl
        Default:
          Mode: Concurrency
          MaxErrors: 0
          Concurrency: 1
      OOSAssumeRole:
        Label:
          en: OOSAssumeRole
          zh-cn: OOS扮演的RAM角色
        Type: String
    RamRole: '{{ OOSAssumeRole }}'
    Tasks:
      - Name: GetServiceInstance
        Description:
          en: Views the compute nest supplier instances
          zh-cn: 计算巢商家侧获取服务实例
        Action: ACS::SelectTargets
        Properties:
          ResourceType: ALIYUN::ComputeNestSupplier::Instance
          RegionId: '{{ RegionId }}'
          Filters:
            - '{{ Targets }}'
        Outputs:
          InstanceIds:
            Type: List
            ValueSelector: ServiceInstances[].ServiceInstanceId
    Metadata:
      ALIYUN::OOS::Interface:
        ParameterGroups:
          - Parameters:
              - RegionId
              - Targets
            Label:
              default:
                zh-cn: 配置参数
                en: Configure Parameters
          - Parameters:
              - RateControl
              - OOSAssumeRole
            Label:
              default:
                zh-cn: 高级选项
                en: Control Options
    {
      "FormatVersion": "OOS-2019-06-01",
      "Parameters": {
        "RegionId": {
          "Type": "String",
          "Label": {
            "en": "RegionId",
            "zh-cn": "地域ID"
          },
          "AssociationProperty": "RegionId",
          "Default": "{{ ACS::RegionId }}"
        },
        "Targets": {
          "Type": "Json",
          "Label": {
            "en": "TargetInstance",
            "zh-cn": "目标实例"
          },
          "AssociationProperty": "Targets",
          "AssociationPropertyMetadata": {
            "ResourceType": "ALIYUN::ComputeNestSupplier::Instance",
            "RegionId": "RegionId"
          }
        },
        "RateControl": {
          "Label": {
            "en": "RateControl",
            "zh-cn": "任务执行的并发比率"
          },
          "Type": "Json",
          "AssociationProperty": "RateControl",
          "Default": {
            "Mode": "Concurrency",
            "MaxErrors": 0,
            "Concurrency": 1
          }
        },
        "OOSAssumeRole": {
          "Label": {
            "en": "OOSAssumeRole",
            "zh-cn": "OOS扮演的RAM角色"
          },
          "Type": "String"
        }
      },
      "RamRole": "{{ OOSAssumeRole }}",
      "Tasks": [
        {
          "Name": "GetServiceInstance",
          "Description": {
            "en": "Views the compute nest supplier instances",
            "zh-cn": "计算巢商家侧获取服务实例"
          },
          "Action": "ACS::SelectTargets",
          "Properties": {
            "ResourceType": "ALIYUN::ComputeNestSupplier::Instance",
            "RegionId": "{{ RegionId }}",
            "Filters": [
              "{{ Targets }}"
            ]
          },
          "Outputs": {
            "InstanceIds": {
              "Type": "List",
              "ValueSelector": "ServiceInstances[].ServiceInstanceId"
            }
          }
        }
      ],
      "Metadata": {
        "ALIYUN::OOS::Interface": {
          "ParameterGroups": [
            {
              "Parameters": [
                "RegionId",
                "Targets"
              ],
              "Label": {
                "default": {
                  "zh-cn": "配置参数",
                  "en": "Configure Parameters"
                }
              }
            },
            {
              "Parameters": [
                "RateControl",
                "OOSAssumeRole"
              ],
              "Label": {
                "default": {
                  "zh-cn": "高级选项",
                  "en": "Control Options"
                }
              }
            }
          ]
        }
      }
    }
  • 根据实例ID选择参数示例

    targets:
      ResourceIds:
        - si-9b136xxxxxxxxxxxxxxx
        - si-f63edxxxxxxxxxxxxxxx
      RegionId: cn-hangzhou
      Type: ResourceIds
    {
      "targets": {
        "ResourceIds": [
          "si-9b1363ae63664f19a156",
          "si-f63ed519cc3445eebdcd"
        ],
        "RegionId": "cn-hangzhou",
        "Type": "ResourceIds"
      }
    }
  • 选择杭州地域服务Id为“"service-xxxx”版本为“4”且状态为已部署的全部服务实例

    targets:
      Type: All
      RegionId: cn-hangzhou
      Parameters:
        Filter:
          - Name: Status
            Value:
              - Deployed
          - Name: 'Version '
            Value:
              - '4'
          - Name: ServiceId
            Value:
              - ervice-ea89c844c3e9430a9b9c
        RegionId: cn-hangzhou
    {
    	"targets": {
    		"Type": "All",
    		"RegionId": "cn-hangzhou",
    		"Parameters": {
    			"Filter": [{
    					"Name": "Status",
    					"Value": [
    						"Deployed"
    					]
    				},
    				{
    					"Name": "Version ",
    					"Value": ["4"]
    				},
    				{
    					"Name": "ServiceId",
    					"Value": ["ervice-ea89c844c3e9430a9b9c"]
    				}
    			],
    			"RegionId": "cn-hangzhou"
    		}
    	}
    }
  • 通过标签选择ECS实例并执行命令模板

    FormatVersion: OOS-2019-06-01
    Description:
      en: Query instances through tags and execute commands..
      zh-cn: 通过标签查询实例并执行命令。
      name-en: Run Command
      name-zh-cn: 发送远程命令
      categories:
        - run_command
        - application_manage
        - computenest
        - tag_operate_resource
    Parameters:
      regionId:
        Type: String
        Label:
          en: RegionId
          zh-cn: 地域ID
        AssociationProperty: RegionId
        Default: '{{ ACS::RegionId }}'
      tags:
        Description:
          name-en: Tags
          name-zh-cn: 标签
          en: format:[{"Key":"k1","Value":"v1"},{"Key":"k2","Value":"v2"}....].
          zh-cn: 输入格式:[{"Key":"k1","Value":"v1"},{"Key":"k2","Value":"v2"}....]
        Type: Json
        AssociationProperty: Tags
      commandType:
        Label:
          en: CommandType
          zh-cn: 命令类型
        AssociationPropertyMetadata:
          LocaleKey: ECSCommandType
        Type: String
        AllowedValues:
          - RunShellScript
          - RunPythonScript
          - RunPerlScript
          - RunBatScript
          - RunPowerShellScript
        Default: RunShellScript
      commandContent:
        Label:
          en: CommandContent
          zh-cn: 命令内容
        Type: String
        MaxLength: 16384
        AssociationProperty: ALIYUN::OOS::Command::CommandContent
        AssociationPropertyMetadata:
          CommandType: ${commandType}
      workingDir:
        Description:
          en: 'Linux instances: under the home directory of the administrator (root user): /root.Windows instances: under the directory where the process of the Cloud Assistant client is located, such asC:\Windows\System32. Please ensure you input the correct directory.'
          zh-cn: Linux系统实例默认在管理员(root用户)的home目录下,即/root。Windows系统实例默认在云助手客户端进程所在目录,例如C:\Windows\System32。请确保您输入的目录是正确的。'
        Label:
          en: WorkingDir
          zh-cn: 运行目录
        Type: String
        Default: ''
        AssociationPropertyMetadata:
          Value:
            - Condition:
                Fn::Or:
                  - Fn::Equals:
                      - ${commandType}
                      - RunShellScript
                  - Fn::Equals:
                      - ${commandType}
                      - RunPythonScript
                  - Fn::Equals:
                      - ${commandType}
                      - RunPerlScript
              Value: /root
            - Condition:
                Fn::Or:
                  - Fn::Equals:
                      - ${commandType}
                      - RunBatScript
                  - Fn::Equals:
                      - ${commandType}
                      - RunPowerShellScript
              Value: C:\\Windows\\System32
      timeout:
        Label:
          en: Timeout
          zh-cn: 超时时间
        Type: Number
        Default: 600
      enableParameter:
        Label:
          en: EnableParameter
          zh-cn: 命令中是否包含加密参数或自定义参数
        Type: Boolean
        Default: false
      username:
        Description:
          en: The username that is used to run the command on the ECS instance, length must not exceed 255 characters. Linux system ECS instance, the default is root. Windows system ECS instance, the default is System. Please ensure you input the correct username. <a href="https://www.alibabacloud.com/help/doc-detail/203771.html" target="_blank">See more</a>
          zh-cn: 在ECS实例中执行命令的用户名称,长度不得超过255个字符。Linux系统的实例,默认以root用户执行命令。Windows系统的实例,默认以System用户执行命令。请确保您输入的用户名是正确的。<a href="https://www.alibabacloud.com/help/doc-detail/203771.html" target="_blank">了解更多</a>
        Label:
          en: Username
          zh-cn: 执行命令的用户名称
        Type: String
        Default: ''
      windowsPasswordName:
        Label:
          en: WindowsPasswordName
          zh-cn: 在Windows实例中执行命令的用户的密码名称
        Type: String
        Default: ''
        AssociationProperty: ALIYUN::OOS::SecretParameter::Value
        AssociationPropertyMetadata:
          Visible:
            Condition:
              Fn::Or:
                - Fn::Equals:
                    - ${commandType}
                    - RunBatScript
                - Fn::Equals:
                    - ${commandType}
                    - RunPowerShellScript
      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: ListInstance
        Action: ACS::ExecuteAPI
        Description:
          en: List the eips.
          zh-cn: 通过标签查询instance。
        Properties:
          Service: ECS
          API: ListTagResources
          Parameters:
            RegionId: '{{ regionId }}'
            ResourceType: instance
            Tag: '{{ tags }}'
        Outputs:
          instanceIds:
            Type: List
            ValueSelector: .TagResources.TagResource[].ResourceId
      - Name: runCommand
        Action: ACS::ECS::RunCommand
        Description:
          en: Execute cloud assistant command
          zh-cn: 执行云助手命令
        Properties:
          regionId: '{{ regionId }}'
          commandContent: '{{ commandContent }}'
          instanceId: '{{ ACS::TaskLoopItem }}'
          commandType: '{{ commandType }}'
          workingDir: '{{ workingDir }}'
          timeout: '{{ timeout }}'
          enableParameter: '{{ enableParameter }}'
          username: '{{ username }}'
          windowsPasswordName: '{{ windowsPasswordName }}'
          contentEncoding: PlainText
          parameters: {}
          maxRetryInterval: 300
        Outputs:
          commandOutput:
            Type: String
            ValueSelector: invocationOutput
        Loop:
          Items: '{{ ListInstance.instanceIds }}'
          RateControl: '{{ rateControl }}'
          Outputs:
            commandOutputs:
              AggregateType: Fn::ListJoin
              AggregateField: commandOutput
    Outputs:
      commandOutputs:
        Type: List
        Value: '{{ runCommand.commandOutputs }}'
    Metadata:
      ALIYUN::OOS::Interface:
        ParameterGroups:
          - Parameters:
              - commandType
              - commandContent
              - workingDir
              - timeout
              - enableParameter
              - username
              - windowsPasswordName
            Label:
              default:
                zh-cn: 执行命令选型
                en: run command options
          - Parameters:
              - regionId
              - tags
            Label:
              default:
                zh-cn: 选择实例
                en: Select Ecs Instances
          - Parameters:
              - rateControl
              - OOSAssumeRole
            Label:
              default:
                zh-cn: 高级选项
                en: Control Options
    
    {
      "FormatVersion": "OOS-2019-06-01",
      "Description": {
        "en": "Query instances through tags and execute commands..",
        "zh-cn": "通过标签查询实例并执行命令。",
        "name-en": "Run Command",
        "name-zh-cn": "发送远程命令",
        "categories": [
          "run_command",
          "application_manage",
          "computenest",
          "tag_operate_resource"
        ]
      },
      "Parameters": {
        "regionId": {
          "Type": "String",
          "Label": {
            "en": "RegionId",
            "zh-cn": "地域ID"
          },
          "AssociationProperty": "RegionId",
          "Default": "{{ ACS::RegionId }}"
        },
        "tags": {
          "Description": {
            "name-en": "Tags",
            "name-zh-cn": "标签",
            "en": "format:[{\"Key\":\"k1\",\"Value\":\"v1\"},{\"Key\":\"k2\",\"Value\":\"v2\"}....].",
            "zh-cn": "输入格式:[{\"Key\":\"k1\",\"Value\":\"v1\"},{\"Key\":\"k2\",\"Value\":\"v2\"}....]"
          },
          "Type": "Json",
          "AssociationProperty": "Tags"
        },
        "commandType": {
          "Label": {
            "en": "CommandType",
            "zh-cn": "命令类型"
          },
          "AssociationPropertyMetadata": {
            "LocaleKey": "ECSCommandType"
          },
          "Type": "String",
          "AllowedValues": [
            "RunShellScript",
            "RunPythonScript",
            "RunPerlScript",
            "RunBatScript",
            "RunPowerShellScript"
          ],
          "Default": "RunShellScript"
        },
        "commandContent": {
          "Label": {
            "en": "CommandContent",
            "zh-cn": "命令内容"
          },
          "Type": "String",
          "MaxLength": 16384,
          "AssociationProperty": "ALIYUN::OOS::Command::CommandContent",
          "AssociationPropertyMetadata": {
            "CommandType": "${commandType}"
          }
        },
        "workingDir": {
          "Description": {
            "en": "Linux instances: under the home directory of the administrator (root user): /root.Windows instances: under the directory where the process of the Cloud Assistant client is located, such asC:\\Windows\\System32. Please ensure you input the correct directory.",
            "zh-cn": "Linux系统实例默认在管理员(root用户)的home目录下,即/root。Windows系统实例默认在云助手客户端进程所在目录,例如C:\\Windows\\System32。请确保您输入的目录是正确的。'"
          },
          "Label": {
            "en": "WorkingDir",
            "zh-cn": "运行目录"
          },
          "Type": "String",
          "Default": "",
          "AssociationPropertyMetadata": {
            "Value": [
              {
                "Condition": {
                  "Fn::Or": [
                    {
                      "Fn::Equals": [
                        "${commandType}",
                        "RunShellScript"
                      ]
                    },
                    {
                      "Fn::Equals": [
                        "${commandType}",
                        "RunPythonScript"
                      ]
                    },
                    {
                      "Fn::Equals": [
                        "${commandType}",
                        "RunPerlScript"
                      ]
                    }
                  ]
                },
                "Value": "/root"
              },
              {
                "Condition": {
                  "Fn::Or": [
                    {
                      "Fn::Equals": [
                        "${commandType}",
                        "RunBatScript"
                      ]
                    },
                    {
                      "Fn::Equals": [
                        "${commandType}",
                        "RunPowerShellScript"
                      ]
                    }
                  ]
                },
                "Value": "C:\\\\Windows\\\\System32"
              }
            ]
          }
        },
        "timeout": {
          "Label": {
            "en": "Timeout",
            "zh-cn": "超时时间"
          },
          "Type": "Number",
          "Default": 600
        },
        "enableParameter": {
          "Label": {
            "en": "EnableParameter",
            "zh-cn": "命令中是否包含加密参数或自定义参数"
          },
          "Type": "Boolean",
          "Default": false
        },
        "username": {
          "Description": {
            "en": "The username that is used to run the command on the ECS instance, length must not exceed 255 characters. Linux system ECS instance, the default is root. Windows system ECS instance, the default is System. Please ensure you input the correct username. <a href=\"https://www.alibabacloud.com/help/doc-detail/203771.html\" target=\"_blank\">See more</a>",
            "zh-cn": "在ECS实例中执行命令的用户名称,长度不得超过255个字符。Linux系统的实例,默认以root用户执行命令。Windows系统的实例,默认以System用户执行命令。请确保您输入的用户名是正确的。<a href=\"https://www.alibabacloud.com/help/doc-detail/203771.html\" target=\"_blank\">了解更多</a>"
          },
          "Label": {
            "en": "Username",
            "zh-cn": "执行命令的用户名称"
          },
          "Type": "String",
          "Default": ""
        },
        "windowsPasswordName": {
          "Label": {
            "en": "WindowsPasswordName",
            "zh-cn": "在Windows实例中执行命令的用户的密码名称"
          },
          "Type": "String",
          "Default": "",
          "AssociationProperty": "ALIYUN::OOS::SecretParameter::Value",
          "AssociationPropertyMetadata": {
            "Visible": {
              "Condition": {
                "Fn::Or": [
                  {
                    "Fn::Equals": [
                      "${commandType}",
                      "RunBatScript"
                    ]
                  },
                  {
                    "Fn::Equals": [
                      "${commandType}",
                      "RunPowerShellScript"
                    ]
                  }
                ]
              }
            }
          }
        },
        "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": "ListInstance",
          "Action": "ACS::ExecuteAPI",
          "Description": {
            "en": "List the eips.",
            "zh-cn": "通过标签查询instance。"
          },
          "Properties": {
            "Service": "ECS",
            "API": "ListTagResources",
            "Parameters": {
              "RegionId": "{{ regionId }}",
              "ResourceType": "instance",
              "Tag": "{{ tags }}"
            }
          },
          "Outputs": {
            "instanceIds": {
              "Type": "List",
              "ValueSelector": ".TagResources.TagResource[].ResourceId"
            }
          }
        },
        {
          "Name": "runCommand",
          "Action": "ACS::ECS::RunCommand",
          "Description": {
            "en": "Execute cloud assistant command",
            "zh-cn": "执行云助手命令"
          },
          "Properties": {
            "regionId": "{{ regionId }}",
            "commandContent": "{{ commandContent }}",
            "instanceId": "{{ ACS::TaskLoopItem }}",
            "commandType": "{{ commandType }}",
            "workingDir": "{{ workingDir }}",
            "timeout": "{{ timeout }}",
            "enableParameter": "{{ enableParameter }}",
            "username": "{{ username }}",
            "windowsPasswordName": "{{ windowsPasswordName }}",
            "contentEncoding": "PlainText",
            "parameters": {},
            "maxRetryInterval": 300
          },
          "Outputs": {
            "commandOutput": {
              "Type": "String",
              "ValueSelector": "invocationOutput"
            }
          },
          "Loop": {
            "Items": "{{ ListInstance.instanceIds }}",
            "RateControl": "{{ rateControl }}",
            "Outputs": {
              "commandOutputs": {
                "AggregateType": "Fn::ListJoin",
                "AggregateField": "commandOutput"
              }
            }
          }
        }
      ],
      "Outputs": {
        "commandOutputs": {
          "Type": "List",
          "Value": "{{ runCommand.commandOutputs }}"
        }
      },
      "Metadata": {
        "ALIYUN::OOS::Interface": {
          "ParameterGroups": [
            {
              "Parameters": [
                "commandType",
                "commandContent",
                "workingDir",
                "timeout",
                "enableParameter",
                "username",
                "windowsPasswordName"
              ],
              "Label": {
                "default": {
                  "zh-cn": "执行命令选型",
                  "en": "run command options"
                }
              }
            },
            {
              "Parameters": [
                "regionId",
                "tags"
              ],
              "Label": {
                "default": {
                  "zh-cn": "选择实例",
                  "en": "Select Ecs Instances"
                }
              }
            },
            {
              "Parameters": [
                "rateControl",
                "OOSAssumeRole"
              ],
              "Label": {
                "default": {
                  "zh-cn": "高级选项",
                  "en": "Control Options"
                }
              }
            }
          ]
        }
      }
    }