Template name
ACS-ECS-ScheduleToCleanUpDisks
Template description
Cleans up disks as scheduled. This applies to scenarios in which you want to clean up disks of an Elastic Compute Service (ECS) instance at specified times, such as log files and temporary files cleaning. When you configure this template, you must specify the following parameters: timerTrigger: the time to trigger the task, regionId: the region of the ECS instance, targets: the ECS instance, and cleanUpInfos: the rules for disk cleaning. After the template is executed, the result is returned.
Template type
Automated
Owner
Alibaba Cloud
Input parameters
Parameter | Description | Type | Required | Default value | Limit |
timerTrigger | The type of the scheduled task. | Json | Yes | ||
targets | The Elastic Compute Service (ECS) instances whose disks in which you want to clean up data. | Json | Yes | ||
cleanUpInfos | The rule for cleaning up data in disks. | String | Yes | Regular expression for string verification: [""\s]+ | | |
regionId | The region ID. | String | No | {{ ACS::RegionId }} | |
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 | OOSServiceRole |
Output parameters
Parameter | Description | Type |
commandOutputs | List |
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-ScheduleToCleanUpDisks.yml at GitHub.
Template content
FormatVersion: OOS-2019-06-01
Description:
en: 'Schedule to clean up disks, applicable to scenarios that require periodic management and cleaning of disk space on ECS instances, such as automatic log file cleanup and deletion of temporary files. During configuration, users need to provide the following required parameter information: Timer Trigger (timerTrigger), which defines when the cleanup task is triggered, Region ID (regionId), which specifies the region of the ECS instances where the disks will be cleaned, Target Instances (targets), which defines the specific ECS instances to be operated on, and Cleanup Rule (cleanUpInfos), which specifies the specific disk cleanup rules. Upon execution, the template will return a list of the output results of the cleanup command, enabling users to verify the status of the disk cleanup operations.'
zh-cn: the description in Chinese
name-en: Cleanup Disks
name-zh-cn: the description in Chinese
categories:
- time_trigger
- application_manage
- computenest
Parameters:
timerTrigger:
Type: Json
Label:
en: TimerTrigger
zh-cn: the description in Chinese
AssociationProperty: ALIYUN::OOS::Component::TimerTrigger
AssociationPropertyMetadata:
MinuteInterval: 30
regionId:
Type: String
Label:
en: RegionId
zh-cn: the description in Chinese
AssociationProperty: RegionId
Default: '{{ ACS::RegionId }}'
targets:
Type: Json
Label:
en: TargetInstance
zh-cn: the description in Chinese
AssociationProperty: Targets
AssociationPropertyMetadata:
ResourceType: 'ALIYUN::ECS::Instance'
RegionId: regionId
Status: Running
cleanUpInfos:
Description:
en: 'Format: 3d|/root/log/|*.log,3h|/root/log/|*.access,30m|C:\Users\Administrator\log\|*.log.'
zh-cn: the description in Chinese
Label:
en: CleanUpRule
zh-cn: the description in Chinese
Type: String
AssociationProperty: ALIYUN::OOS::Component::CleanUpInfo
AllowedPattern: "^[^\"$`'\\s]+$"
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: OOSServiceRole
RamRole: '{{ OOSAssumeRole }}'
Tasks:
- Name: timerTrigger
Action: 'ACS::TimerTrigger'
Description:
en: Triggers a task as scheduled by specifying type and expression
zh-cn: the description in Chinese
Properties:
Type:
'Fn::Select':
- type
- '{{timerTrigger}}'
Expression:
'Fn::Select':
- expression
- '{{timerTrigger}}'
EndDate:
'Fn::Select':
- endDate
- '{{ timerTrigger }}'
TimeZone:
'Fn::Select':
- timeZone
- '{{ timerTrigger }}'
- 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: cleanUpDisk
Action: 'ACS::ECS::CleanUpDisk'
Description:
en: Execute cloud assistant command to clean up disk
zh-cn: the description in Chinese
Properties:
regionId: '{{ regionId }}'
instanceId: '{{ ACS::TaskLoopItem }}'
cleanUpInfos: '{{ cleanUpInfos }}'
Loop:
RateControl: '{{ rateControl }}'
Items: '{{ getInstance.instanceIds }}'
Outputs:
commandOutputs:
AggregateType: Fn::ListJoin
AggregateField: commandOutput
Outputs:
commandOutput:
Type: String
ValueSelector: commandOutput
Outputs:
commandOutputs:
Type: List
Value: '{{ cleanUpDisk.commandOutputs }}'
Metadata:
ALIYUN::OOS::Interface:
ParameterGroups:
- Parameters:
- timerTrigger
Label:
default:
zh-cn: the description in Chinese
en: The time of cleanup disk
- Parameters:
- cleanUpInfos
Label:
default:
zh-cn: the description in Chinese
en: The rule of cleanup disk
- Parameters:
- regionId
- targets
Label:
default:
zh-cn: the description in Chinese
en: Select ECS Instances
- Parameters:
- rateControl
- OOSAssumeRole
Label:
default:
zh-cn: the description in Chinese
en: Control Options