Open ghost opened 6 years ago
In case anyone else is experiencing similar issues, for now my workaround has been running local-exec
provisioners:
# Sleep because local-exec was running before ssh was started newly created instances.
provisioner "local-exec" {
command = "sleep 10s"
}
provisioner "local-exec" {
command = "cd ${var.knife_path} && knife node delete ${aws_instance.bastion_server.tags.Name} -y && knife client delete ${aws_instance.bastion_server.tags.Name} -y || true"
}
provisioner "local-exec" {
command = "cd ${var.knife_path} && knife bootstrap ${aws_instance.bastion_server.public_ip} -N ${aws_instance.bastion_server.tags.Name} -r 'role[bastion]' -x ubuntu -i ${var.provisioner_key} --sudo"
}
provisioner "local-exec" {
command = "cd ${var.knife_path} && knife node run_list add ${aws_instance.bastion_server.tags.Name} 'role[bastion]'"
}
hey @BMonsalvatge - I was experiencing this same issue, but then discovered it was because I was putting the path to my private key in improperly.
Compare this
variable "chef_key" {
default = "/path/to/file.pem"
}
...
user_key = "${var.chef_key}"
With this
user_key = "${file("/path/to/file.pem")}"
The file interpolation is returning the contents of the pem key as a string, while the variable is just returning the path. You must use the file interpolation, or I assume you can even post the whole private key directly if you really want to....
https://www.terraform.io/docs/configuration/interpolation.html#file-path-
Hey @stobias123 - Not sure how I missed that one considering I put it in the connection block above. Thanks for pointing that out! Resolved my issue.
This issue was originally opened by @BMonsalvatge as hashicorp/terraform#18461. It was migrated here as a result of the provider split. The original body of the issue is below.
Terraform Version
Terraform Configuration Files
Expected Behavior
Chef should have bootstrapped the node.
Actual Behavior
Additionally on the server the contents of
/etc/chef/
are the following:contents of
client.rb
are:If I add the correct key to /etc/chef/validator.pem & edit the client.rb file to look like the following,
sudo chef-client
works and connects to the chef server:Steps to Reproduce
terraform init
terraform apply
Additional Context
References