Linux 使用cloudinit用户数据
我有一个简单的cloudinit用户数据,我正在将其传递给ec2。我通过右键单击实例并在其中设置用户数据,在ec2实例上设置此数据 以下是我的cloud init用户数据Linux 使用cloudinit用户数据,linux,amazon-ec2,cloud-init,Linux,Amazon Ec2,Cloud Init,我有一个简单的cloudinit用户数据,我正在将其传递给ec2。我通过右键单击实例并在其中设置用户数据,在ec2实例上设置此数据 以下是我的cloud init用户数据 #cloud-config runcmd: - [ ls, -l, / ] - [ sh, -xc, "echo $(date) ': hello world!'" ] - [ sh, -c, echo "=========hello world'=========" ] - [ touch, /home/ec2-u
#cloud-config
runcmd:
- [ ls, -l, / ]
- [ sh, -xc, "echo $(date) ': hello world!'" ]
- [ sh, -c, echo "=========hello world'=========" ]
- [ touch, /home/ec2-user/hello.txt ]
final_message: "The system is finally up, after 10 seconds"
我从中获得了这个示例,并添加了touch命令
我的期望是在/var/log/cloud-init.log上看到数据。但我在那里看不到。此外,我没有看到任何错误,也没有看到创建的hello.txt文件
有什么我遗漏的吗
我正在运行一个amazon linux实例,而不是ubuntu实例。这是您的第三个命令中的语法错误:
- [ sh, -c, echo "=========hello world'=========" ]
这是一个工作用户数据:
#cloud-config
runcmd:
- [ ls, -l, / ]
- [ sh, -xc, 'echo $(date) ": hello world!"' ]
- [ sh, -c, 'echo "=========hello world========="' ]
- [ touch, /home/ec2-user/hello.txt ]
final_message: "The system is finally up"
output : { all : '| tee -a /var/log/cloud-init-output.log' }
注意,它仅在
/var/log/cloud init.log
中显示cloud init执行日志。指定output
指令后,您应该在/var/log/cloud init output.log
中看到输出。AFAIK,用户数据仅在实例启动时起作用(而不是每个实例启动时)。因此,我不确定“查看/更改用户数据”选项是如何工作的。不管怎样,我只是厌倦了你说的话,我可以复制这个问题。然而,当我运行curl-L时,我可以看到新的/修改的用户数据http://169.254.169.254/latest/user-data/
来自实例。但是,用户数据并没有达到我预期的效果。可能是,因为它只在实例启动时起作用。我当然有兴趣看到这个问题的答案+1.我的解决方案是放弃将Amazon Linux与cloud-init结合使用。感谢您提供有关cloud-init-output.log的提示。AWS文档提到了这一点,但我sort-a遗漏了它,没有找到预期的cloud init output.log
。