Template name
ACS-ECS-BulkyDownloadFileAndRunCommand
Template description
Downloads a file to multiple Elastic Compute Service (ECS) instances at a time and runs a Cloud Assistant command on the ECS instances.
Template type
Automated
Owner
Alibaba Cloud
Input parameters
Parameter | Description | Type | Required | Default value | Limit |
targets | The ECS instances to which you want to download the file. | Json | Yes | ||
sourcePath | The source path of the file. | String | Yes | ||
destinationDir | The directory to which the file is downloaded in the ECS instances. | String | Yes | ||
regionId | The region ID. | String | No | {{ ACS::RegionId }} | |
sourceType | The type of the file. | String | No | local | |
commandContent | The command content. | String | No | # # Sample Java code # java_pid= # if [[ $java_pid ]];then # kill -9 $java_pid # fi # nohup java -jar *.jar & | The command can be up to 16,384 bytes in length. |
workingDir | The directory in which the command is to be run on the ECS instances. | String | No | "" | |
timeout | The timeout period for running the command on the ECS instance. | Number | No | 600 | |
rateControl | The rate control settings. | Json | No | {'Mode': 'Concurrency', 'MaxErrors': 0, 'Concurrency': 10} | |
OOSAssumeRole | The Resource Access Management (RAM) role that is assumed by CloudOps Orchestration Service (OOS). | String | No | "" |
Output parameters
None
Permission policy that is required to execute the template
{
"Version": "1",
"Statement": [
{
"Action": [
"ecs:DescribeInstances",
"ecs:DescribeInvocationResults",
"ecs:DescribeInvocations",
"ecs:RunCommand"
],
"Resource": "*",
"Effect": "Allow"
}
]
}
References
For more information, see ACS-ECS-BulkyDownloadFileAndRunCommand.yml at GitHub.
Template content
FormatVersion: OOS-2019-06-01
Description:
en: Bulky downLoad file to instances and run command
zh-cn: the description in Chinese
name-en: ACS-ECS-BulkyDownloadFileAndRunCommand
name-zh-cn: the description in Chinese
categories:
- instance_manage
- application_manage
Parameters:
regionId:
Type: String
Label:
en: RegionId
zh-cn: the description in Chinese
AssociationProperty: RegionId
Default: '{{ ACS::RegionId }}'
targets:
Label:
en: TargetInstance
zh-cn: the description in Chinese
Type: Json
Description:
en: <p class="p">Precautions:</p> <ul class="ul"> <li class="li"><font color='red'>Download via https requires the ECS instance to enable public network access </font></li><li class="li"><font color='red'>Downloading via oss requires an ECS instance to configure a RAM role, <a href='https://www.alibabacloud.com/help/en/operation-orchestration-service/latest/download-multiple-objects-to-an-instance#vOk3w'>Reference Document</a></font></li>
zh-cn: the description in Chinese
AssociationProperty: Targets
AssociationPropertyMetadata:
ResourceType: 'ALIYUN::ECS::Instance'
RegionId: regionId
sourceType:
Type: String
Description:
en: Local uploaded files cannot exceed 500M
zh-cn: the description in Chinese
Label:
en: SourceType
zh-cn: the description in Chinese
AllowedValues:
- local
- oss
- https
Default: local
AssociationPropertyMetadata:
LocaleKey: DownloadFileType
RegionId: ${regionId}
sourcePath:
Type: String
Label:
en: SourcePath
zh-cn: the description in Chinese
AssociationProperty: ALIYUN::OOS::File::FileUrl
AssociationPropertyMetadata:
FileType: ${sourceType}
RegionId: ${regionId}
destinationDir:
Label:
en: DestinationDir
zh-cn: the description in Chinese
Type: String
commandContent:
Label:
en: CommandContent
zh-cn: the description in Chinese
Type: String
MaxLength: 16384
AssociationProperty: ALIYUN::OOS::Command::CommandContent
AssociationPropertyMetadata:
CommandType: RunShellScript
Default: |
# # Sample Java code
# java_pid=`ps -ef | grep java | grep -v grep | awk '{print$2}'`
# if [[ $java_pid ]];then
# kill -9 $java_pid
# fi
# nohup java -jar *.jar &
workingDir:
Label:
en: WorkingDir
zh-cn: the description in Chinese
Description:
en: 'The directory where the created command runs on the ECS instances.Linux instances: under the home directory of the administrator (root user): /root.Windows instances: under the directory where the process of the Cloud Assistant client is located, such asC:\Windows\System32.'
zh-cn: the description in Chinese '
Type: String
Default: ''
timeout:
Label:
en: Timeout
zh-cn: the description in Chinese
Type: Number
Default: 600
rateControl:
Label:
en: RateControl
zh-cn: the description in Chinese
Type: Json
AssociationProperty: RateControl
Default:
Mode: Concurrency
MaxErrors: 0
Concurrency: 10
OOSAssumeRole:
Label:
en: OOSAssumeRole
zh-cn: the description in Chinese
Type: String
Default: ''
RamRole: '{{ OOSAssumeRole }}'
Tasks:
- Name: getInstance
Description:
en: Views the ECS instances
zh-cn: the description in Chinese
Action: 'ACS::SelectTargets'
Properties:
ResourceType: 'ALIYUN::ECS::Instance'
RegionId: '{{ regionId }}'
Filters:
- '{{ targets }}'
Outputs:
instanceIds:
Type: List
ValueSelector: 'Instances.Instance[].InstanceId'
- Name: downloadFileAndRunCommand
Action: ACS::ECS::DownloadFileAndRunCommand
Description:
en: Downloads file to the ECS instances adn run command
zh-cn: the description in Chinese
Properties:
regionId: '{{ regionId }}'
instanceId: '{{ ACS::TaskLoopItem }}'
sourceType: '{{ sourceType }}'
sourcePath: '{{ sourcePath }}'
destinationDir: '{{ destinationDir }}'
commandContent: '{{ commandContent }}'
workingDir: '{{ workingDir }}'
timeout: '{{ timeout }}'
Loop:
Items: '{{ getInstance.instanceIds }}'
RateControl: '{{ rateControl }}'
Metadata:
ALIYUN::OOS::Interface:
ParameterGroups:
- Parameters:
- sourceType
- sourcePath
- commandContent
- destinationDir
- workingDir
- timeout
Label:
default:
zh-cn: the description in Chinese
en: Configure Parameters
- Parameters:
- regionId
- targets
Label:
default:
zh-cn: the description in Chinese
en: Select Instances
- Parameters:
- rateControl
- OOSAssumeRole
Label:
default:
zh-cn: the description in Chinese
en: Control Options