How to run commands which require sudo using Capistrano V3?

hak*_*8or 9 shell sudo capistrano

I would like to be able to run apt-get update and then install a few new programs (tmux) along with apt-get upgrade on all my servers when running cap setup but am fumbling around with the apparent lack of documentation regarding sudo on v3.

The gotcha on the v3 release page for sudo makes me sad. http://www.capistranorb.com/2013/06/01/release-announcement.html

For example, here is how I think sudo should work based on some googling, but I keep getting asked for a password.

desc "Check that we can access everything"
task :setup do
  on roles(:web) do
    uptime = capture(:uptime)
    info "Uptime: #{uptime}"
    sudo "apt-get update"
  end
end
Run Code Online (Sandbox Code Playgroud)

随着下面的响应我手动输入终端中的密码似乎根本没有做任何事情(没有错误,没有响应).

DEBUG [e47a40c6] Finished in 4.646 seconds command successful.
DEBUG [e47a40c6]         05:37:52 up 14:36,  3 users,  load average: 0.00, 0.01, 0.05
DEBUG [e47a40c6] Finished in 4.646 seconds command successful.
 INFO Uptime: 05:37:52 up 14:36,  3 users,  load average: 0.00, 0.01, 0.05
 INFO [d194a520] Running /usr/bin/env sudo apt-get update on 192.168.1.126
DEBUG [d194a520] Command: /usr/bin/env sudo apt-get update
DEBUG [d194a520]        [sudo] password for deploy:
Run Code Online (Sandbox Code Playgroud)

此外,是否有一个我没有看到哪个地方保存了已更新到v3的文档?

Osc*_*ett 12

从这个页面看,建议使用sudo和capistrano 3的方法是设置无密码的sudo.

  • 我环顾四周,找到了这个非常棒的指南,根据你的推荐为用户和特定命令设置无字sudo:http://www.davidverhasselt.com/2008/01/27/passwordless-sudo/我会保持这个问题的开放性再过几天,看看是否有人有更好的想法,或者是否有人指出我这样做错了. (4认同)