【发布时间】:2023-12-03 16:06:02
【问题描述】:
我正在使用 Terraform 部署 EC2 实例并在其上安装 boostacks wiki。 Bookstack 提供了一个 bash 脚本,可以自动在 ubuntu 服务器上安装文件,但是,当我在 user_data 中运行脚本时,什么也没有发生。我不确定为什么? 这是 user_Data 代码
user_data= <<-EOF
# Ensure you have read the above information about what this script does before executing these commands.
sudo apt install wget
# Download the script
wget https://raw.githubusercontent.com/BookStackApp/devops/main/scripts/installation-ubuntu-18.04.sh
# Make it executable
chmod a+x installation-ubuntu-18.04.sh
# Run the script with admin permissions
sudo ./installation-ubuntu-18.04.sh
EOF
tags ={
Name ="bookstacks_terraform"
}
脚本成功运行后,应提示用户进入域。但是,什么都没有发生,我不知道如何测试它。
【问题讨论】:
-
user_data只是传递给在 EC2 实例中运行的软件的原始数据对象。由 EC2 实例中的软件决定如何处理它。 -
既然你提到了 Ubuntu Server,我敢打赌解释你的脚本的软件是cloud-init,所以我为此添加了一个标签,这样你的问题可能对拥有云的人可见-初始化知识。
-
然而,我在这里要强调的主要一点是
cloud-init——因此它可能作为执行你提供的脚本的一部分运行的任何其他软件——在它具有的上下文中运行没有直接的输入或输出。它会像安装在系统上的服务器一样启动,其唯一的输出方式是写入日志文件,并且无法提示输入。 -
您可能需要找到不同的策略才能在没有任何提示的情况下获得所需的结果。
-
希望更熟悉 cloud-init 的人可以提出典型的调试技术;我假设它正在向a log file 写入一些有用的信息,但我不知道 Ubuntu Server AMI 包含哪些日志记录设置,因此不知道在哪里可以找到生成的日志。
标签: amazon-web-services amazon-ec2 terraform cloud-init