【发布时间】:2016-05-24 16:51:16
【问题描述】:
我正在使用AWS Two-tier example,我直接复制粘贴了整个内容。 terraform apply 一直工作到它尝试通过 SSH 连接到创建的 EC2 实例的位置。在最终失败之前,它会循环多次给出此输出。
aws_instance.web (remote-exec): Connecting to remote host via SSH...
aws_instance.web (remote-exec): Host: 54.174.8.144
aws_instance.web (remote-exec): User: ubuntu
aws_instance.web (remote-exec): Password: false
aws_instance.web (remote-exec): Private key: false
aws_instance.web (remote-exec): SSH Agent: true
最终,它失败了:
Error applying plan:
1 error(s) occurred:
* ssh: handshake failed: ssh: unable to authenticate, attempted methods [none publickey], no supported methods remain
Terraform does not automatically rollback in the face of errors.
Instead, your Terraform state file has been partially updated with
any resources that successfully completed. Please address the error
above and apply again to incrementally change your infrastructure.
我四处搜索并看到一些较旧的帖子/问题说翻转agent=false,我也尝试过,没有任何变化或成功。我怀疑这个例子是开箱即用的,但我没有做任何可能会破坏它的剪裁或修改。我在 OS X 10.10.5 上使用通过 homebrew 安装的 terraform 0.6.11。
补充细节:
resource "aws_instance" "web" {
# The connection block tells our provisioner how to
# communicate with the resource (instance)
connection {
# The default username for our AMI
user = "ubuntu"
# The connection will use the local SSH agent for authentication.
agent = false
}
instance_type = "t1.micro"
# Lookup the correct AMI based on the region
# we specified
ami = "${lookup(var.aws_amis, var.aws_region)}"
# The name of our SSH keypair we created above.
key_name = "${aws_key_pair.auth.id}"
# Our Security group to allow HTTP and SSH access
vpc_security_group_ids = ["${aws_security_group.default.id}"]
# We're going to launch into the same subnet as our ELB. In a production
# environment it's more common to have a separate private subnet for
# backend instances.
subnet_id = "${aws_subnet.default.id}"
# We run a remote provisioner on the instance after creating it.
# In this case, we just install nginx and start it. By default,
# this should be on port 80
provisioner "remote-exec" {
inline = [
"sudo apt-get -y update",
"sudo apt-get -y install nginx",
"sudo service nginx start"
]
}
}
从变量 tf 文件中:
variable "key_name" {
description = "Desired name of AWS key pair"
default = "test-keypair"
}
variable "key_path" {
description = "key location"
default = "/Users/n8/dev/play/.ssh/terraform.pub"
}
但我可以用这个命令 ssh:
ssh -i ../.ssh/terraform ubuntu@w.x.y.z
【问题讨论】:
-
你能用普通的ssh连接吗?您的代理中有密钥吗?
-
我可以手动 ssh。我不确定我是否理解你的第二个问题,所以答案可能是“不”。你能解释一下吗?
-
请用信息更新问题如何你可以从命令行
ssh以及你如何进行身份验证。 -
添加了一些信息。谢谢!
标签: amazon-web-services ssh amazon-ec2 sdn terraform