All Products
Search
Document Center

CloudOps Orchestration Service:ACS-ECS-BulkyRunCommandInSLBDefaultServerGroup

Last Updated:Nov 26, 2024

Template name

ACS-ECS-BulkyRunCommandInSLBDefaultServerGroup

Execute Now

Template description

Runs a command on multiple Elastic Compute Service (ECS) instances in the default server group of a Server Load Balancer (SLB) instance at a time.

Template type

Automated

Owner

Alibaba Cloud

Input parameters

Parameter

Description

Type

Required

Default value

Limit

loadBalancerId

The ID of the SLB instance.

String

Yes

commandType

The type of the Cloud Assistant command.

String

No

RunShellScript

commandContent

The Cloud Assistant command to be run on the ECS instances.

String

No

echo hello

rateControl

The rate control settings.

Json

No

{'Mode': 'Concurrency', 'MaxErrors': 0, 'Concurrency': 1}

OOSAssumeRole

The Resource Access Management (RAM) role that is assumed by CloudOps Orchestration Service (OOS).

String

No

""

Output parameters

Parameter

Description

Type

commandOutputs

List

Permission policy that is required to execute the template

{
    "Version": "1",
    "Statement": [
        {
            "Action": [
                "slb:DescribeLoadBalancerAttribute",
                "slb:SetBackendServers"
            ],
            "Resource": "*",
            "Effect": "Allow"
        },
        {
            "Action": [
                "ecs:DescribeInvocationResults",
                "ecs:DescribeInvocations",
                "ecs:RunCommand"
            ],
            "Resource": "*",
            "Effect": "Allow"
        }
    ]
}

References

For more information, see ACS-ECS-BulkyRunCommandInSLBDefaultServerGroup.yml at GitHub.

Template content

FormatVersion: OOS-2019-06-01
Description:
  en: Bulky run command on ECS instances of  default server group
  zh-cn: the description in Chinese
  name-en: ACS-ECS-BulkyRunCommandInSLBDefaultServerGroup
  name-zh-cn: the description in Chinese
  categories:
    - slb_management
Parameters:
  loadBalancerId:
    Label:
      en: LoadBalancerId
      zh-cn: the description in Chinese
    Type: String
  commandType:
    Label:
      en: CommandType
      zh-cn: the description in Chinese
    Type: String
    AllowedValues:
      - RunBatScript
      - RunPowerShellScript
      - RunShellScript
    Default: RunShellScript
  commandContent:
    Label:
      en: CommandContent
      zh-cn: the description in Chinese
    Type: String
    AssociationProperty: Code
    Default: echo hello
  rateControl:
    Label:
      en: RateControl
      zh-cn: the description in Chinese
    Type: Json
    AssociationProperty: RateControl
    Default:
      Mode: Concurrency
      MaxErrors: 0
      Concurrency: 1
  OOSAssumeRole:
    Label:
      en: OOSAssumeRole
      zh-cn: the description in Chinese
    Type: String
    Default: ''
RamRole: '{{ OOSAssumeRole }}'
Tasks:
  - Name: describeLoadBalancerAttribute
    Action: ACS::ExecuteApi
    Description:
      en: Views loadbalancer attribute
      zh-cn: the description in Chinese
    Properties:
      Service: SLB
      API: DescribeLoadBalancerAttribute
      Parameters:
        LoadBalancerId: '{{ loadBalancerId }}'
    Outputs:
      BackendServers:
        Type: List
        ValueSelector: BackendServers.BackendServer[]
      port:
        Type: Number
        ValueSelector: ListenerPorts.ListenerPort[]
  - Name: runCommand
    Action: ACS::ECS::ElegantRunCommandInSLBDefaultServerGroup
    Description:
      en: Execute cloud assistant command
      zh-cn: the description in Chinese
    Properties:
      loadBalancerId: '{{ LoadBalancerId }}'
      commandContent: '{{ commandContent }}'
      commandType: '{{ commandType }}'
      serverId:
        'Fn::Select':
          - ServerId
          - '{{ ACS::TaskLoopItem }}'
      weight:
        'Fn::Select':
          - Weight
          - '{{ ACS::TaskLoopItem }}'
      type:
        'Fn::Select':
          - Type
          - '{{ ACS::TaskLoopItem }}'
      port: '{{ describeLoadBalancerAttribute.port }}'
    Loop:
      RateControl: '{{ rateControl }}'
      Items: '{{ describeLoadBalancerAttribute.BackendServers }}'
      Outputs:
        commandOutputs:
          AggregateType: Fn::ListJoin
          AggregateField: commandOutput
    Outputs:
      commandOutput:
        Type: String
        ValueSelector: commandOutput
Outputs:
  commandOutputs:
    Type: List
    Value: '{{ runCommand.commandOutputs }}'
Metadata:
  ALIYUN::OOS::Interface:
    ParameterGroups:
      - Parameters:
          - loadBalancerId
          - commandType
          - commandContent
        Label:
          default:
            zh-cn: the description in Chinese
            en: Configure Parameters
      - Parameters:
          - rateControl
          - OOSAssumeRole
        Label:
          default:
            zh-cn: the description in Chinese
            en: Control