-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathACS::ECS::CopyLinuxInstanceFileFromOSS.yml
100 lines (100 loc) · 3.03 KB
/
ACS::ECS::CopyLinuxInstanceFileFromOSS.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
FormatVersion: OOS-2019-06-01
Description:
name-en: ACS::ECS::CopyLinuxInstanceFileFromOSS
name-zh-cn: 复制OSS中的文件到ECS实例
en: Copies the file from OSS to ECS instance by run command
zh-cn: 通过执行命令复制OSS中的文件到ECS实例
Parameters:
regionId:
Description:
en: The ID of region
zh-cn: 地域ID
Type: String
Default: '{{ ACS::RegionId }}'
instanceId:
Description:
en: The ID of ECS Instance
zh-cn: ECS实例ID
Type: String
MaxLength: 30
MinLength: 1
instanceRole:
Description:
en: The ramRole attached on the instance
zh-cn: ECS实例上挂载的RAM角色
Type: String
srcUrl:
Description:
en: Current directory of the file in OSS
zh-cn: 文件在OSS中的存储目录
Type: String
destUrl:
Description:
en: Target directory for file copy in linux instance
zh-cn: 文件在实例中的目录
Type: String
Tasks:
- Name: checkInstanceReady
Action: ACS::CheckFor
Description:
en: Checks wether the ECS instance is in Running status
zh-cn: 检查实例是否处于运行中状态
Properties:
Service: ECS
API: DescribeInstances
Parameters:
RegionId: '{{ regionId }}'
InstanceIds:
- '{{ instanceId }}'
DesiredValues:
- Running
PropertySelector: Instances.Instance[].Status
- Name: checkInstanceRAMRoleReady
Action: ACS::CheckFor
Description:
en: Checks wether the instance RAMrole is available
zh-cn: 检查实例上挂载的RAM角色是否可用
Properties:
Service: ECS
API: DescribeInstanceRAMRole
Parameters:
RegionId: '{{ regionId }}'
InstanceIds:
- '{{ instanceId }}'
RamRoleName: '{{ instanceRole }}'
DesiredValues:
- "{{ instanceRole }}"
PropertySelector: InstanceRamRoleSets.InstanceRamRoleSet[].RamRoleName
- Name: runCommand
Action: ACS::ECS::RunCommand
Description:
en: Runs command to copy file
zh-cn: 执行复制文件的命令
Properties:
regionId: '{{ regionId }}'
commandContent:
Fn::Join:
- ' '
- - if [ ! -d oos ];then
mkdir /root/oos;
fi;
- cd /root/oos;
- if [ ! -f "/root/oos/ossutil64" ];then
wget https://oos-public-{{ACS::RegionId}}.oss-{{ ACS::RegionId }}-internal.aliyuncs.com/x64/ossutil64 && chmod 755 ossutil64;
fi;
- echo "[Credentials]" > oss.cfg;
- echo "languague=EN" >> oss.cfg;
- echo "endpoint=https://oss-{{ ACS::RegionId }}-internal.aliyuncs.com" >> oss.cfg;
- echo "[AkService]" >> oss.cfg;
- echo "ecsAk=http://100.100.100.200/latest/meta-data/Ram/security-credentials/{{ instanceRole }}" >> oss.cfg;
- ./ossutil64 --config-file oss.cfg cp {{ SrcUrl }} {{ DestUrl }}
instanceId: '{{ InstanceId }}'
commandType: RunShellScript
Outputs:
commandOutput:
Type: String
ValueSelector: invocationOutput
Outputs:
result:
Type: String
Value: '{{ runCommand.commandOutput }}'