我在让我的 Chef 食谱克隆一个私人仓库时遇到了很多麻烦。好吧,我昨天让它工作了,但是在“cheffin”了我的 Vagrant 盒子六次之后,我把它弄坏了。我是厨师新手,你可能猜到了。
按照此处的 deploy_resource 指南,我创建了 deploy.rb 配方(缩短):
deploy_branch "/var/www/html/ps" do
repo git@github.com:simonmorley/private-v2.git
ssh_wrapper "/tmp/.ssh/chef_ssh_deploy_wrapper.sh"
branch "rails4"
migrate false
environment "RAILS_ENV" => node[:ps][:rails_env]
purge_before_symlink %w{conf data log tmp public/system public/assets}
create_dirs_before_symlink []
symlinks( # the arrow is sort of reversed:
"conf" => "conf", # current/conf -> shared/conf
"data" => "data", # current/data -> shared/data
"log" => "log", # current/log -> shared/log
"tmp" => "tmp", # current/tmp -> shared/tmp
"system" => "public/system", # current/public/system -> shared/system
"assets" => "public/assets" # current/public/assets -> shared/assets
)
scm_provider Chef::Provider::Git # is the default, for svn: Chef::Provider::Subversion
notifies :restart, "service[ps]"
notifies :restart, "service[nginx]"
end
默认情况下,我有以下内容来创建目录等。
directory "/tmp/.ssh" do
action :create
owner node[:base][:username]
group node[:base][:username]
recursive true
end
template "/tmp/.ssh/chef_ssh_deploy_wrapper.sh" do
source "chef_ssh_deploy_wrapper.sh.erb"
owner node[:base][:username]
mode 0770
end
# Put SSH private key to be used with SSH wrapper
template "/tmp/.ssh/id_deploy" do
source "id_rsa.pub.erb"
owner node[:base][:username]
mode 0600
end
在包装器中:
#!/bin/sh
exec ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i "/tmp/.ssh/id_deploy" "$@"
我创建了一个公钥并将其上传到 github。
当我部署配方时,它给了我一个错误:
deploy_branch[/var/www/html/ps] action deployEnter passphrase for key '/tmp/.ssh/id_deploy':
观察我没有设置密码...因此必须丢失私钥..
偶然地,我从配方中删除了 id_deploy 键,删除了文件夹并再次运行它。低,看,它开始工作......原因是 id_rsa.pub && id_rsa 文件在我手动生成它们以进行测试时位于 /root/.ssh 中。
我不明白我在这里做错了什么。因此,我的问题是:
- 我需要部署到的每个节点上的私钥和公钥吗?文档没有提到这一点。
- 这不应该部署为非 root 用户吗?我在角色文件中设置了一个用户..
- 为什么 ssh_wrapper 没有做它应该做的事情