Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
741 views
in Technique[技术] by (71.8m points)

ssh - Git authentication in Chef

When deploying an application with Chef, I've got the code base set to be cloned from a private github repository with the following resource:

git '/mnt/application' do
    repository '[email protected]:organization/repository'

    reference 'master'
    action :sync

    user node.application.user
    group node.application.user
end

However, after scanning the documentation for the git resource, I can't see how you supply the key file for authentication. I'm also confused as to how to store this key in a data bag, as the file contains a bunch of new lines. Any ideas?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
ssh_wrapper "ssh -i /some/path/id_rsa"

In case someone comes across this, the above didn't work for me, I kept getting the error:

error: cannot run ssh -i /some/path/id_rsa: No such file or directory

What specifying ssh_wrapper does is it sets the GIT_SSH environment variable, and it turns out you can't provide parameters in the GIT_SSH environment variable (see Git clone with custom SSH using GIT_SSH error).

Instead, you would need to write your script to a file first, then set GIT_SSH to it.

So:

file "/some/path/git_wrapper.sh" do
  owner "your_user"
  mode "0755"
  content "#!/bin/sh
exec /usr/bin/ssh -i /some/path/id_rsa "$@""
end

And change the git resource part to:

git "/opt/mysources/couch" do
  repository "git://git.apache.org/couchdb.git"
  reference "master"
  action :sync
  ssh_wrapper "/some/path/git_wrapper.sh"
end

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...