すべてのプロダクト
Search
ドキュメントセンター

CloudOps Orchestration Service:テンプレートの作成

最終更新日:Sep 09, 2026

CloudOps Orchestration Service (OOS) コンソールでカスタムテンプレートを作成し、複数の ECS インスタンスでコマンドを一括実行します。

  1. CloudOps Orchestration Service コンソールにログインします。

  2. ナビゲーションペインで、自動タスク > マイテンプレート の順に選択し、テンプレートの作成 をクリックします。

  3. サンプルテンプレートまたはローカルファイルからテンプレートを作成できます。

    • サンプルテンプレートから [Batch Run Commands] を選択し、次のステップ をクリックします。

    • コマンドの一括実行用の YAML または JSON テンプレートファイルがある場合は、ローカルファイルをアップロードして 次のステップ をクリックします。

      コマンド一括実行テンプレート

      FormatVersion: OOS-2019-06-01
      Description: 複数の ECS インスタンスでコマンドを一括実行します。
      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: ECS インスタンスを取得します。
          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: クラウドアシスタントのコマンドを実行します。
          Properties:
            instanceId: '{{ ACS::TaskLoopItem }}'
            commandType: RunShellScript
            commandContent: |-
              #!/bin/bash
      
              ##### スクリプトの実行開始時に呼び出すと、現在のタイムスタンプとPIDが出力されます。
              function job_start()
              {
                  now=`date +'%Y-%m-%d %H:%M:%S'`
                  echo "[$now][$$] job_start"
              }
      
              ##### 戻り値が 0 の場合は成功、それ以外の場合は失敗を表します。
              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": "複数の ECS インスタンスでコマンドを一括実行します。",
        "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": "ECS インスタンスを取得します。",
            "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": "クラウドアシスタントのコマンドを実行します。",
            "Properties": {
              "instanceId": "{{ ACS::TaskLoopItem }}",
              "commandType": "RunShellScript",
              "commandContent": "#!/bin/bash\n\n##### スクリプトの実行開始時に呼び出すと、現在のタイムスタンプとPIDが出力されます。\nfunction job_start()\n{\n    now=`date +'%Y-%m-%d %H:%M:%S'`\n    echo \"[$now][$$] job_start\"\n}\n\n##### 戻り値が 0 の場合は成功、それ以外の場合は失敗を表します。\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. (任意) Get ECS Instances タスクは事前設定されています。変更するには、テンプレートパラメーター セクションで targets パラメーターを設定します。

    説明

    実行を作成する際に、コマンドを実行する ECS インスタンスを選択し、必要な情報を入力します。詳細については、「実行の作成」をご参照ください。

  5. コマンド内容 エリアでスクリプトの内容を編集し、テンプレートの作成 をクリックします。

  6. テンプレート名 を入力し、完全な作成 をクリックします。

関連ドキュメント

  • テンプレートを作成したら、実行を開始します。詳細については、「実行の作成」をご参照ください。

  • テンプレート内のすべてのタスクを確認し、リスクを許容できる場合は、手動での確認なしで実行を行えます。詳細については、「完全自動実行」をご参照ください。

  • テンプレート内の個々のタスクを1つずつ実行するには、実行の作成時にシングルステップモードを選択します。詳細については、「シングルステップ実行」をご参照ください。