(AWS Opsworks)Terraform Chef供应:错误:无法进行身份验证

时间:2017-10-23 19:55:31

标签: amazon-web-services chef terraform aws-opsworks

Terraform新手,我正在尝试在创建实例后将节点引导至chef。

这是文件:

resource "aws_instance" "jenkinsNode" {

provisioner "remote-exec" {
connection {
  user = "ubuntu"
  private_key = "${file("~/key/mykey.pem")}"
  host = "${aws_instance.jenkinsNode.public_ip}" 
}

inline = [
  "sudo mkdir -p /etc/chef/trusted_certs",
  "sudo curl --silent --show-error --retry 3 --location --output 
\"/etc/chef/trusted_certs/opsworks-cm-ca-2016-root.pem\" 
\"https://opsworks-cm-us-assets.s3.amazonaws.com/misc/opsworks-cm-ca-2016-root.pem\""
 ]
}

provisioner "chef" {

environment     = "_default"
run_list        = ["android-aws-nodes::updateAndroidSdk"]
node_name       = "jenkinsNodeOnDemandUpdate"
secret_key      = "${file("~/chef/mobile-chef-aws/.chef/private.pem")}"
server_url      = "https://my-opsworks-server.io/organizations/default"
recreate_client = true
user_name       = "delivery"
user_key        = "${file("~/chef/mobile-chef-aws/.chef/private.pem")}"
version         = "12.8.1"
}

connection {
user = "ubuntu"
private_key = "${file("~/key/jenkins-main.pem")}"
}

 count = 1
 instance_type = "c4.8xlarge"
 ami = "ami-0000000"
 key_name = "mykey"
 subnet_id = "subnet-00000000"
 vpc_security_group_ids = ["sg-00000000"]
}

我在尝试应用上述代码时运行时收到以下错误。我连接并启动引导过程,但它一直抱怨它无法找到私有(我相信在运行“客户端创建”时创建。我ssh进入实例,我没有看到ubuntu.pem在/ etc / chef /目录:

已更新     aws_instance.jenkinsNode(chef):错误:无法通过密钥/etc/chef/delivery.pem向https://mobile-b9oer25dyrts1qor.us-east-1.opsworks-cm.io/organizations/default/进行身份验证     aws_instance.jenkinsNode(chef):响应:用户或客户端“交付”的签名无效     aws_instance.jenkinsNode(chef):清理用户密钥......

Error applying plan:

1 error(s) occurred:

* aws_instance.jenkinsNode: 1 error(s) occurred:

* Command "sudo knife client create jenkinsNodeOnDemandUpdate -d -f /etc/chef/client.pem -c /etc/chef/client.rb -u ubuntu --key /etc/chef/ubuntu.pem" exited with non-zero exit status: 100

1 个答案:

答案 0 :(得分:0)

登录时没有密钥,因为它在失败的bootstrap

后立即删除
aws_instance.jenkinsNode (chef): Cleanup user key...

仔细检查运行Terraform的计算机上的密钥(~/key/mykey.pem)是否格式正确。它也应该加载$file或作为字符串:

user_key        = "${file("~/key/mykey.pem")}"

只需仔细检查Terraform是否支持~