Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chef running git clone results in host key verification error

I am using Chef, invoked by Capistrano.

There is a directive to clone a repository using git.

git node['rails']['rails_root'] do
  repository "[email protected]:/myproj.git"
  reference "master"
  action :sync
  user node['rails']['rails_user']
  group node['rails']['rails_group']
end

When it gets to this point, I get:

 ** [out :: 10.1.1.1] STDERR: Host key verification failed.

So, I need to add a "known_hosts" entry. No problem. But to which user? The core of my problem is that I have no idea which user is executing what commands, and if they are invoking sudo, etc.

I've run keyscan to populate the known_hosts of root, and the user I ssh in as, to no avail.

Note, this git repo is read-protected, and requires ssh key access.

like image 663
cmonkey Avatar asked Apr 30 '13 18:04

cmonkey


3 Answers

Another way to solve https://github.com/opscode-cookbooks/ssh_known_hosts

this worked for me

like image 197
goutham Avatar answered Oct 24 '22 09:10

goutham


You can use an ssh wrapper approach. Look here for details.

Briefly do the following steps

First, create a file in the cookbooks/COOKBOOK_NAME/files/default directory that is named wrap-ssh4git.sh and which contains the following:

#!/usr/bin/env bash
/usr/bin/env ssh -o "StrictHostKeyChecking=no" $1 $2

Then, use the following block for your deployment:

directory "/tmp/private_code/.ssh" do
  owner "ubuntu"
  recursive true
end

cookbook_file "/tmp/private_code/wrap-ssh4git.sh" do
  source "wrap-ssh4git.sh"
  owner "ubuntu"
  mode 00700
end

deploy "private_repo" do
  repo "[email protected]:acctname/private-repo.git"
  user "ubuntu"
  deploy_to "/tmp/private_code"
  action :deploy
  ssh_wrapper "/tmp/private_code/wrap-ssh4git.sh"
end
like image 5
Vlad Avatar answered Oct 24 '22 07:10

Vlad


The git repository will be cloned as user node['rails']['rails_user'] (via https://docs.chef.io/resource_git.html) - I assume that users known_hosts file is the one you have to modify.

like image 2
cmur2 Avatar answered Oct 24 '22 09:10

cmur2