使用cloud-init用户数据

时间:2014-05-23 01:56:58

标签: linux amazon-ec2 cloud-init

我有一个简单的cloud-init用户数据,我将其传递给ec2。我通过右键单击实例并在那里设置用户数据,在ec2实例上设置了这些数据。

以下是我的cloud-init用户数据

#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"

我从here得到了这个例子,我添加了触摸命令

我的期望是查看/var/log/cloud-init.log上的数据。但我不认为那里。此外,我没有看到任何错误,也没有看到创建的hello.txt文件

我有什么遗失的东西吗?

我正在运行亚马逊linux实例而不是ubuntu实例

1 个答案:

答案 0 :(得分:5)

第3个命令中出现语法错误:

- [ 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执行日志。在指定/var/log/cloud-init-output.log指令后,您应该在output中看到输出。