我正在使用Capistrano调用的厨师。
有一个使用git克隆存储库的指令。
git node['rails']['rails_root'] do
repository "git@myrepo.com:/myproj.git"
reference "master"
action :sync
user node['rails']['rails_user']
group node['rails']['rails_group']
end
当达到这一点时,我得到:
** [out :: 10.1.1.1] STDERR: Host key verification failed.
所以,我需要添加一个“known_hosts”条目。没问题。但是对哪个用户?我的问题的核心是我不知道哪个用户正在执行什么命令,以及他们是否正在调用sudo等。
我已经运行了密钥扫描来填充root的known_hosts,而我用ssh的用户也无济于事。
注意,这个git repo是读保护的,需要ssh密钥访问。
答案 0 :(得分:6)
解决https://github.com/opscode-cookbooks/ssh_known_hosts
的另一种方法这对我有用
答案 1 :(得分:5)
您可以使用ssh包装器方法。查看here了解详细信息。
简要执行以下步骤
首先,在cookbooks / COOKBOOK_NAME / files / default目录中创建一个名为wrap-ssh4git.sh且包含以下内容的文件:
#!/usr/bin/env bash
/usr/bin/env ssh -o "StrictHostKeyChecking=no" $1 $2
然后,使用以下块进行部署:
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 "git@github.com:acctname/private-repo.git"
user "ubuntu"
deploy_to "/tmp/private_code"
action :deploy
ssh_wrapper "/tmp/private_code/wrap-ssh4git.sh"
end
答案 2 :(得分:2)
git存储库将以用户node['rails']['rails_user']
克隆(通过https://docs.chef.io/resource_git.html) - 我假设用户known_hosts文件是您必须修改的文件。
答案 3 :(得分:1)
我已解决此问题,如下所示
_home_dir = nil
node['etc']['passwd'].each do |user, data|
if user.eql? node['jenkins']['username']
_home_dir = data['dir']
end
end
key_config ="Host *\n\tStrictHostKeyChecking no\n"
file "#{_home_dir}/.ssh/config" do
owner node['jenkins']['username']
group node['jenkins']['username']
mode "0600"
content key_config
end