0

I am trying to clone from a private Bitbucket repo in test kitchen. I have went as far as configuring a key pair for Bitbucket use and when I run kitchen login can manually run the command as root:

git clone <repo> <directory>

But when running a kitchen converge, it ALWAYS fails. I can't figure it out for the life of me. Here is what I am doing in my recipe:

directory '/root/.ssh/' do
  owner "root"
  group "root"
  mode '0700'
  action :create
end

template '/root/.ssh/id_rsa' do
  source 'id_rsa.erb'
  owner 'root'
  group 'root'
  mode '0600'
end

package 'git'

file "/root/git_wrapper.sh" do
  owner "root"
  mode "0755"
  content "#!/bin/sh\nexec /usr/bin/ssh -i /root/.ssh/id_rsa \"$@\""
end

git "/etc/myrepo" do
  # The following line ensures that our repo-specific deployment
  # ssh-key will be used for all clone & fetch operations.
  repository 'git@bitbucket.org:myrepo/myrepo.git'
  checkout_branch "master"
  ssh_wrapper "/root/git_wrapper.sh"
  user "root"
  action :sync
end

I am at a complete loss on this, especially if I can run the git command inside the container. Here is the stacktrace I get:

   Running handlers:
   [2018-03-21T14:38:36+00:00] ERROR: Running exception handlers
   Running handlers complete
   [2018-03-21T14:38:36+00:00] ERROR: Exception handlers complete
   Chef Client failed. 14 resources updated in 13 seconds
   [2018-03-21T14:38:36+00:00] FATAL: Stacktrace dumped to /tmp/kitchen/cache/chef-stacktrace.out
   [2018-03-21T14:38:36+00:00] FATAL: Please provide the contents of the stacktrace.out file if you file a bug report
   [2018-03-21T14:38:36+00:00] ERROR: git[/etc/myrepo] (bsd-env-mtarep::mtarep line 50) had an error: Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0], but received '128'
   ---- Begin output of git ls-remote "git@bitbucket.org:myrepo/myrepo.git" "HEAD" ----
   STDOUT:
   STDERR: Host key verification failed.
   fatal: Could not read from remote repository.

   Please make sure you have the correct access rights
   and the repository exists.
   ---- End output of git ls-remote "git@bitbucket.org:myrepo/myrepo.git" "HEAD" ----
   Ran git ls-remote "git@bitbucket.org:myrepo/myrepo.git" "HEAD" returned 128
   [2018-03-21T14:38:36+00:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)

Can someone advise what I need to do to fix this?

ryekayo
  • 2,341
  • 3
  • 23
  • 51
  • 1
    looks like you need to drop a '/root/.ssh/known_hosts` file with the public host key of bitbucket.org – lamont Mar 23 '18 at 17:14
  • Thats exactly what was going on!! I actually was able to fix it by updating my SSH wrapper script.. – ryekayo Mar 23 '18 at 17:15

1 Answers1

1

It sounds like the key might be wrong? Also obligatory plug for the poise-git cookbook which makes this a bit simpler.

coderanger
  • 52,400
  • 4
  • 52
  • 75
  • I found a way to work around this.. I had to add a flag that disables StrictHostKeyChecking and UserKnownHostsFile and that seemed to have worked. – ryekayo Mar 21 '18 at 20:36