Todos os produtos
Search
Central de documentação

CloudOps Orchestration Service:Use common parameters in a task template

Última atualização: Sep 06, 2026

Se vários modelos de tarefa compartilham um valor de configuração, armazene-o no Parameter Store como uma variável global. Reutilizar esse valor entre os modelos aumenta a eficiência operacional e garante a consistência. Este tópico descreve como usar parâmetros comuns em um modelo de tarefa.

Pré-requisitos

Crie um parâmetro comum no Parameter Store. Para obter mais informações, consulte Create a common parameter.

Procedimento

Usar o console do OOS

Este exemplo utiliza um public task template para executar um comando remoto. Um parâmetro comum chamado time_out com valor 600 define o tempo limite do modelo como 600.

  1. Faça logon no console do CloudOps Orchestration Service.

  2. No painel de navegação à esquerda, escolha Automated Tasks > > Common Task Templates. Localize o modelo desejado e clique em Create an execution.image

  3. Insira as informações básicas e clique em Next: Set Parameters.

  4. À esquerda de Timeout Period, clique no ícone image. Selecione o parâmetro comum criado (neste exemplo, time_out) para definir o tempo limite como 600. Em seguida, selecione as instâncias de destino e clique em Next.image

  5. Verifique se as informações da tarefa estão corretas e clique em Create.

  6. Após clicar em Create, a página de detalhes da execução será exibida. Confirme se o valor do campo de destino está correto.image

Usar um parâmetro em um modelo

Para utilizar um parâmetro comum em um modelo, referencie-o usando o formato {{ oos:parameter_name }}.

O exemplo a seguir demonstra como criar um modelo que executa um comando do Cloud Assistant em uma instância ECS. Nesse modelo, um parâmetro comum chamado time_out com valor 600 define o tempo limite como 600.

  1. Faça logon no console do CloudOps Orchestration Service.

  2. No painel de navegação à esquerda, escolha Automated Tasks > > Custom Task Templates e clique em Create Template. O modelo abaixo mostra como referenciar o parâmetro comum time_out. Na linha 98, o parâmetro timeout está definido como '{{ oos:time_out }}'.

    FormatVersion: OOS-2019-06-01
    Description: Runs Cloud Assistant commands on multiple ECS instances in batches. This is useful for managing multiple ECS instances at once for tasks such as application management and resource tagging. During configuration, you must provide the following required parameters: Region ID (regionId) to specify the region of the target ECS instances, Resource Type (resourceType) to determine the target instance type, such as an ECS instance or a managed instance, and Target Instances (targets) to select the specific instances to operate on. Other parameters include Command Type (commandType) to specify the command type, such as a shell script or Python script, and Command Content (commandContent) for the specific command or script content. After the execution, the template returns the output of the batch operation, which allows you to verify the execution status.
    Parameters:
      regionId:
        Type: String
        Label: Region ID
        AssociationProperty: RegionId
        Default: '{{ ACS::RegionId }}'
      resourceType:
        Type: String
        Label: Resource Type
        AssociationPropertyMetadata:
          LocaleKey: TargetResourceType
        AllowedValues:
          - ALIYUN::ECS::Instance
          - ALIYUN::ECS::ManagedInstance
        Default: ALIYUN::ECS::Instance
      targets:
        Type: Json
        Label: Target Instances
        AssociationProperty: Targets
        AssociationPropertyMetadata:
          ResourceType: resourceType
          RegionId: regionId
          Status: Running
      commandType:
        Label: Command Type
        AssociationPropertyMetadata:
          LocaleKey: ECSCommandType
        Type: String
        AllowedValues:
          - RunShellScript
          - RunPythonScript
          - RunPerlScript
          - RunBatScript
          - RunPowerShellScript
        Default: RunShellScript
      commandContent:
        Label: Command Content
        Type: String
        MaxLength: 16384
        AssociationProperty: ALIYUN::OOS::Command::CommandContent
        AssociationPropertyMetadata:
          CommandType: ${commandType}
      workingDir:
        Description: 'For Linux instances, the default directory is the home directory of the administrator (root user), which is /root. For Windows instances, the default directory is where the Cloud Assistant client process is located, such as C:\Windows\System32. Make sure that the directory you enter is correct.'
        Label: Working Directory
        Type: String
        Default: ''
      enableParameter:
        Label: Specifies whether the command contains encrypted or custom parameters.
        Type: Boolean
        Default: false
      username:
        Description: The username for running the command on the ECS instance. The username cannot exceed 255 characters. On Linux instances, the command is run as the root user by default. On Windows instances, the command is run as the System user by default. Make sure that the username you enter is correct. <a href="https://www.alibabacloud.com/help/doc-detail/203771.html" target="_blank">Learn more</a>
        Label: Username for command execution
        Type: String
        Default: ''
      windowsPasswordName:
        Label: The name of the password for the user on a Windows instance.
        Type: String
        Default: ''
      rateControl:
        Label: The concurrency rate for the task execution.
        Type: Json
        AssociationProperty: RateControl
        Default:
          Mode: Concurrency
          MaxErrors: 0
          Concurrency: 10
      OOSAssumeRole:
        Label: The RAM role that OOS assumes.
        Type: String
        Default: ''
    RamRole: '{{ OOSAssumeRole }}'
    Tasks:
      - Name: getInstance
        Description: Obtains ECS instances.
        Action: ACS::SelectTargets
        Properties:
          ResourceType: '{{ resourceType }}'
          RegionId: '{{ regionId }}'
          Filters:
            - '{{ targets }}'
        Outputs:
          instanceIds:
            Type: List
            ValueSelector: Instances.Instance[].InstanceId
      - Name: runCommand
        Action: ACS::ECS::RunCommand
        Description: Runs the Cloud Assistant command.
        Properties:
          regionId: '{{ regionId }}'
          commandContent: '{{ commandContent }}'
          instanceId: '{{ ACS::TaskLoopItem }}'
          commandType: '{{ commandType }}'
          workingDir: '{{ workingDir }}'
          timeout: '{{ oos:time_out }}'
          enableParameter: '{{ enableParameter }}'
          username: '{{ username }}'
          windowsPasswordName: '{{ windowsPasswordName }}'
        Loop:
          RateControl: '{{ rateControl }}'
          Items: '{{ getInstance.instanceIds }}'
          Outputs:
            commandOutputs:
              AggregateType: Fn::ListJoin
              AggregateField: commandOutput
        Outputs:
          commandOutput:
            Type: String
            ValueSelector: invocationOutput
    Outputs:
      commandOutputs:
        Type: List
        Value: '{{ runCommand.commandOutputs }}'
  3. Após criar o modelo, clique em Execute. Insira os parâmetros necessários e inicie a execução.

  4. Clique na tarefa Run Cloud Assistant Command e, em seguida, clique em Child Executions. Clique em um ID de execução para visualizar os detalhes da execução filha.

  5. Na seção Execution Steps and Results, clique em Input. Observe que o parâmetro timeout foi definido como 600, correspondente ao valor do parâmetro comum time_out.