我正在使用terraform自动创建EC2实例并安装LAMP堆栈。我正在使用cloud-init来获取用户数据。 AWS控制台显示呈现的用户数据。但是,系统日志显示未执行命令。系统日志似乎随机显示了不同的问题。任何见解都表示赞赏!
terraform 0.10.8 Amazon Linux AMI最新版本
在配置阶段有时会看到以下错误。
Starting cloud-init: Cloud-init v. 0.7.6 running 'modules:config'
Loaded plugins: priorities, update-motd, upgrade-helper
/dev/fd/11: line 1: /sbin/plymouthd: No such file or directory
有时在cloud-init“init”阶段会看到以下警告。
cloud-init[2442]: util.py[WARNING]: Failed loading yaml
blob-init[2442]: util.py[WARNING]: Failed loading yaml blob
cloud-init[2442]: util.py[WARNING]: Failed at merging in cloud config part from part-001
以下代码
resource "aws_instance" "ec2_min" {
ami = "${var.ami}"
instance_type = "${var.instance_type}"
vpc_security_group_ids = ["${data.aws_security_group.ec2_sg.id}"]
iam_instance_profile = "${var.instance_profile}"
associate_public_ip_address = "${var.associate_public_ip_address}"
subnet_id = "${data.aws_subnet.subnet.id}"
key_name = "${aws_key_pair.ssh_key.key_name}"
user_data = "${data.template_file.lamp_install.rendered}"
tags {
Name = "${var.instance_name}"
}
}
data "template_file" "lamp_install" {
template = "${file("${var.cloud_init_conf}")}"
}
#cloud-config
repo_update: true
repo_upgrade: all
packages:
- httpd24
- php70
- mysql56-server
- php70-mysqlnd
runcmd:
- service httpd start
- chkconfig httpd on
- [ sh, -c, "usermod -a -G apache ec2-user" ]
- [ sh, -c, "chown -R ec2-user:apache /var/www" ]
- chmod 2775 /var/www
- [ find, /var/www, -type, d, -exec, chmod, 2775, {}, + ]
- [ find, /var/www, -type, f, -exec, chmod, 0664, {}, + ]
- service mysqld start
- chkconfig mysqld on