我尝试使用不同的ssh_options在同一阶段运行capistrano v.3任务 .
我的production.rb说:
set :stage, :production
set :user, 'deploy'
set :ssh_options, { user: 'deploy' }
使用此配置,capistrano与用户 deploy 连接,这对于其余的tak是正确的 . 但是我需要将它连接到一个特定的任务 an_other_user ,它在服务器中配置得很好 . 然后我的食谱说:
...
tasks with original user
...
task :my_task_with_an_other_user do
set :user, 'an_other_user'
set :ssh_options, { user: 'an_other_user' }
on roles(:all) do |host|
execute :mkdir, '-p', 'mydir'
end
end
...
other tasks with original user
...
执行时:
cap production namespace:my_task_with_an_other_user
capistrano使ssh conexion与original:user“deploy”(在production.rb中声明的用户) .
如何在任务中更改用户和/或ssh_options?
2 回答
卡皮斯特拉诺3
我很难找到解决方案 . 但是解决方案比版本2好得多.Cap团队做得很好 . 确保你已将Capistrano更新为3.2.x这就是诀窍:
确保'deploy'和'foo'用户都可以进入框中 . 在您的任务中,使用
on
关键字:其他陷阱:
确保某些Capistrano任务跳过您添加的其他无释放角色 . 否则,它可能会在部署期间导致文件权限问题 . 例如 .
capistrano/bundler
扩展名需要覆盖默认值bundler_roles
卡皮斯特拉诺2
我曾经有一个自定义函数来关闭和重新连接ssh会话 .
将以下方法放在
deploy.rb
中 . 调用with_user
切换ssh会话 . 稍微简化的版本:用法:
@activars的答案对我不起作用 . 因为当我为一个环境定义了几个角色时 - 只部署了一个:(
所以我的解决方案是创建几个环境,例如 production.rb 和 productionroot.rb .
productionroot的内容为no_release = true标志 - 就像你指定的那样:
之后我创建了运行的sh脚本