All Products
Search
Document Center

CloudOps Orchestration Service:Create a template

Last Updated:Sep 10, 2026

Create a custom template in the CloudOps Orchestration Service (OOS) console to batch-run commands on multiple ECS instances.

  1. Log on to the CloudOps Orchestration Service console.

  2. In the navigation pane on the left, choose Automated Task > Custom Template, and click Create Template.

  3. You can create a template from a sample template or a local file.

    • From the sample templates, select Batch Run Commands and click Next Step.

    • If you have a YAML or JSON template file for running batch commands, upload the local file and click Next Step.

      Batch command template

      FormatVersion: OOS-2019-06-01
      Description: Runs commands on multiple ECS instances in a batch.
      Parameters:
        targets:
          Label:
            en: TargetInstance
            zh-cn: Target Instance
          Type: Json
          AssociationProperty: Targets
          AssociationPropertyMetadata:
            ResourceType: ALIYUN::ECS::Instance
            RegionId: regionId
        rateControl:
          Label:
            en: RateControl
            zh-cn: Concurrent rate for task execution
          Type: Json
          AssociationProperty: RateControl
          Default:
            Mode: Concurrency
            MaxErrors: 0
            Concurrency: 10
      Tasks:
        - Name: getInstance
          Description: Obtains ECS instances.
          Action: ACS::SelectTargets
          Properties:
            ResourceType: ALIYUN::ECS::Instance
            Filters:
              - '{{ targets }}'
          Outputs:
            instanceIds:
              Type: List
              ValueSelector: Instances.Instance[].InstanceId
        - Name: runCommand
          Action: ACS::ECS::RunCommand
          Description: Runs a Cloud Assistant command.
          Properties:
            instanceId: '{{ ACS::TaskLoopItem }}'
            commandType: RunShellScript
            commandContent: |-
              #!/bin/bash
      
              ##### This can be called when the script starts to run. It prints the current timestamp and PID.
              function job_start()
              {
                  now=`date +'%Y-%m-%d %H:%M:%S'`
                  echo "[$now][$$] job_start"
              }
      
              ##### If the return value is 0, the execution is successful. Otherwise, the execution failed.
              job_start
            regionId: '{{ ACS::RegionId }}'
            workingDir: /root
            enableParameter: false
            timeout: 600
            username: ''
            parameters: {}
            windowsPasswordName: ''
          Outputs:
            invocationOutput:
              Type: String
              ValueSelector: invocationOutput
          Loop:
            Items: '{{ getInstance.instanceIds }}'
            RateControl: '{{ rateControl }}'
            Outputs:
              invocationOutputs:
                AggregateType: Fn::ListJoin
                AggregateField: invocationOutput
      Outputs:
        invocationOutputs:
          Type: List
          Value: '{{ runCommand.invocationOutputs }}'
      
      {
        "FormatVersion": "OOS-2019-06-01",
        "Description": "Runs commands on multiple ECS instances in a batch.",
        "Parameters": {
          "targets": {
            "Label": {
              "en": "TargetInstance",
              "zh-cn": "Target Instance"
            },
            "Type": "Json",
            "AssociationProperty": "Targets",
            "AssociationPropertyMetadata": {
              "ResourceType": "ALIYUN::ECS::Instance",
              "RegionId": "regionId"
            }
          },
          "rateControl": {
            "Label": {
              "en": "RateControl",
              "zh-cn": "Concurrent rate for task execution"
            },
            "Type": "Json",
            "AssociationProperty": "RateControl",
            "Default": {
              "Mode": "Concurrency",
              "MaxErrors": 0,
              "Concurrency": 10
            }
          }
        },
        "Tasks": [
          {
            "Name": "getInstance",
            "Description": "Obtains ECS instances.",
            "Action": "ACS::SelectTargets",
            "Properties": {
              "ResourceType": "ALIYUN::ECS::Instance",
              "Filters": [
                "{{ targets }}"
              ]
            },
            "Outputs": {
              "instanceIds": {
                "Type": "List",
                "ValueSelector": "Instances.Instance[].InstanceId"
              }
            }
          },
          {
            "Name": "runCommand",
            "Action": "ACS::ECS::RunCommand",
            "Description": "Runs a Cloud Assistant command.",
            "Properties": {
              "instanceId": "{{ ACS::TaskLoopItem }}",
              "commandType": "RunShellScript",
              "commandContent": "#!/bin/bash\n\n##### This can be called when the script starts to run. It prints the current timestamp and PID.\nfunction job_start()\n{\n    now=`date +'%Y-%m-%d %H:%M:%S'`\n    echo \"[$now][$$] job_start\"\n}\n\n##### If the return value is 0, the execution is successful. Otherwise, the execution failed.\njob_start",
              "regionId": "{{ ACS::RegionId }}",
              "workingDir": "/root",
              "enableParameter": false,
              "timeout": 600,
              "username": "",
              "parameters": {},
              "windowsPasswordName": ""
            },
            "Outputs": {
              "invocationOutput": {
                "Type": "String",
                "ValueSelector": "invocationOutput"
              }
            },
            "Loop": {
              "Items": "{{ getInstance.instanceIds }}",
              "RateControl": "{{ rateControl }}",
              "Outputs": {
                "invocationOutputs": {
                  "AggregateType": "Fn::ListJoin",
                  "AggregateField": "invocationOutput"
                }
              }
            }
          }
        ],
        "Outputs": {
          "invocationOutputs": {
            "Type": "List",
            "Value": "{{ runCommand.invocationOutputs }}"
          }
        }
      }
  4. (Optional) The Get ECS Instances task is pre-configured. To modify it, configure the targets parameter in the Template Parameter section.

    Note

    When you create the execution, select the ECS instances on which to run the commands and enter the required information. For more information, see Create an execution.

  5. In the Command Content area, edit the script content, and then click Create Template.

  6. Enter a Template Name and click OK.

References

  • After you create a template, start an execution for it. For more information, see Create an execution.

  • If you have reviewed all tasks in the template and accept the risks, you can run the execution without manual confirmation. For more information, see Fully automatic execution.

  • To run individual tasks in the template one at a time, select single-step mode when you create the execution. For more information, see Single-step execution.