如何使用部署 ssh 密钥在 AWS OpsWorks 上使用 Chef 12 克隆私有存储库

How to use deploy ssh key to clone private repos using Chef 12 on AWS OpsWorks

我可以在 AWS OpsWorks 上使用 Chef 12 克隆 public 存储库,如下所示:

execute "get code" do
user "root"
cwd node['conf-cookbook']['project_root']
command "git clone #{app['app_source']['url']}"
end

但我不知道如何使用部署 ssh 密钥来克隆私有存储库 - 我已经搜索了一段时间并看到了如下可能的解决方案:

git node['conf-cookbook']['app_dir'] do
  repository "ext::ssh -i #{app['app_source']['ssh_key']} -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no #{app['app_source']['url']}"
  checkout_branch "master"
  action :sync
end

错误消息无效:

---- Begin output of git ls-remote "ext::ssh -i -----BEGIN RSA PRIVATE KEY----
MIIJKQIBAAKCAgEApaViIRinBrusrE....[key detail]7xAOmo3NAmqcPxdrOI+hZJHh5KRvrQPLHY
-----END RSA PRIVATE KEY----- -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no git@github.com:harrywang/app-main.git" "HEAD" ----
STDOUT: 
STDERR: Warning: Identity file -----BEGIN not accessible: No such file or directory.
ssh: Could not resolve hostname rsa: Name or service not known 
fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.

有什么帮助吗?谢谢!

-i 采用密钥文件的路径,而不是实际的密钥数据本身。使用 application_git 说明书与 Chef 一起设置部署密钥。

根据@coderanger 的建议,以下工作:

application node['conf-cookbook']['app_dir'] do
  git app['app_source']['url'] do
    deploy_key app['app_source']['ssh_key']
  end
end