當多個執行模板存在相同的配置且需要賦相同的值,可以將配置值儲存在參數倉庫中(類似代碼中的全域變數),然後在多個執行模板中複用,提升操作效率與執行一致性。本文為您介紹如何在執行模板中使用普通參數。
前提條件
已在參數倉庫建立普通參數,更多資訊,請參見建立普通參數。
操作步驟
在OOS控制台使用
本樣本以發送遠程命令公用工作範本為例,使用普通參數time_out(值為600)來設定模板逾時時間為600。
在左側導覽列選擇 選擇一個目標公用模板,點擊建立執行。

填寫好基本資料後點擊下一步:設定參數。
在逾時時間左側單擊
,選擇已建立的普通參數(本文樣本time_out)為逾時時間賦值為500,之後選擇需要執行的執行個體點擊下一步。
查看任務資訊是否正確後,點擊建立。
單擊建立後,進入執行詳情頁面,查看目標欄位的值是否符合預期。

在模板中使用
在模板中使用{{ oos:參數名 }}格式引用普通參數。
本樣本以建立一個在ECS執行雲助手命令的模板為例,使用普通參數time_out(值為600)來設定逾時時間為600。
在左側導覽列選擇 點擊建立模板,模板內容如下。其中第98行,timeout參數使用'{{ oos:time_out }}'格式,表示引用普通參數time_out。
FormatVersion: OOS-2019-06-01 Description: 批量在多台ECS執行個體上運行雲助手命令,適用於需要同時管理多台ECS執行個體的情境,如應用程式管理和資源標記操作等。在配置過程中,使用者需要提供以下必填參數資訊,地區ID(regionId):用於指定需要執行命令的目標ECS執行個體所在的地區,資源類型(resourceType):用於確定目標ECS執行個體的類型(如ECS執行個體或受管執行個體),目標執行個體(targets):用於選擇要操作的具體執行個體列表。參數還包括命令類型(commandType):指定要執行的命令類型(如Shell指令碼、Python指令碼等),以及命令內容(commandContent):具體的命令或指令碼內容。模板在執行後會返回大量操作的輸出結果,方便使用者驗證命令執行的狀態。 Parameters: regionId: Type: String Label: 地區ID AssociationProperty: RegionId Default: '{{ ACS::RegionId }}' resourceType: Type: String Label: 資源類型 AssociationPropertyMetadata: LocaleKey: TargetResourceType AllowedValues: - ALIYUN::ECS::Instance - ALIYUN::ECS::ManagedInstance Default: ALIYUN::ECS::Instance targets: Type: Json Label: 目標執行個體 AssociationProperty: Targets AssociationPropertyMetadata: ResourceType: resourceType RegionId: regionId Status: Running commandType: Label: 命令類型 AssociationPropertyMetadata: LocaleKey: ECSCommandType Type: String AllowedValues: - RunShellScript - RunPythonScript - RunPerlScript - RunBatScript - RunPowerShellScript Default: RunShellScript commandContent: Label: 命令內容 Type: String MaxLength: 16384 AssociationProperty: ALIYUN::OOS::Command::CommandContent AssociationPropertyMetadata: CommandType: ${commandType} workingDir: Description: Linux系統執行個體預設在管理員(root使用者)的home目錄下,即/root。Windows系統執行個體預設在雲助手用戶端進程所在目錄,例如C:\Windows\System32。請確保您輸入的目錄是正確的。' Label: 運行目錄 Type: String Default: '' enableParameter: Label: 命令中是否包含加密參數或自訂參數 Type: Boolean Default: false username: Description: 在ECS執行個體中執行命令的使用者名稱稱,長度不得超過255個字元。Linux系統的執行個體,預設以root使用者執行命令。Windows系統的執行個體,預設以System使用者執行命令。請確保您輸入的使用者名稱是正確的。<a href="https://www.alibabacloud.com/help/doc-detail/203771.html" target="_blank">瞭解更多</a> Label: 執行命令的使用者名稱稱 Type: String Default: '' windowsPasswordName: Label: 在Windows執行個體中執行命令的使用者的密碼名稱 Type: String Default: '' rateControl: Label: 任務執行的並發比率 Type: Json AssociationProperty: RateControl Default: Mode: Concurrency MaxErrors: 0 Concurrency: 10 OOSAssumeRole: Label: OOS扮演的RAM角色 Type: String Default: '' RamRole: '{{ OOSAssumeRole }}' Tasks: - Name: getInstance Description: 擷取ECS執行個體 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: 執行雲助手命令 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 }}'建立模板後,點擊執行。填入必要的參數,然後啟動執行。
點擊執行雲助手命令任務->子執行,點擊執行ID進入子執行。
在執行步驟和結果欄,點擊輸入可以看到逾時時間,已被替換為time_out參數的值600。