以下是我们模板的一部分。我们在那里导出一个路径变量。但是,从模板运行,这不起作用。如果我 SSH 到服务器并运行同一行,它可以工作,我可以使用 gradle。但仅从模板中,它就不会被执行。其他chmod
命令有效,因此该块显然已执行。非常感谢任何帮助。
...
"LaunchConfiguration": {
"Type": "AWS::AutoScaling::LaunchConfiguration",
"Metadata": {
"AWS::CloudFormation::Init": {
"config": {
"packages": {
"yum": {
"java-1.8.0-openjdk-devel": []
}
},
"sources": {
"/opt": "https://services.gradle.org/distributions/gradle-3.4.1-bin.zip",
"/home/ec2-user": "https://github.com/ABC/XYZ/archive/master.zip"
},
"files": {
"/tmp/gradle_config": {
"content": {
"Fn::Join": ["",
[
"#!/bin/bash -ex\n",
"chmod -R 755 gradle-3.4.1/\n",
"export PATH=$PATH:/opt/gradle-3.4.1/bin\n" //<<<< This does not work
]
]
},
"mode": "000500",
"owner": "root",
"group": "root"
},
"/tmp/app_config": {
"content": {
"Fn::Join": ["",
[
"#!/bin/bash -ex\n",
"chmod -R 777 XYZ-master/\n"
]
]
},
"mode": "000500",
"owner": "root",
"group": "root"
}
},
"commands": {
"01_config": {
"command": "/tmp/gradle_config",
"cwd" : "/opt"
},
"02_config": {
"command": "/tmp/app_config",
"cwd" : "/home/ec2-user"
}
}
}
}
}, ...