Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run commands which require sudo using Capistrano V3?

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

With the response of the following with me manually typing in the password in terminal not seeming to do anything at all (no error, no response).

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:

Also, is there a place I am not seeing which holds documentation that has been updated to v3?

like image 668
hak8or Avatar asked Sep 22 '13 02:09

hak8or


1 Answers

From this page, it looks like the suggested way to use sudo with capistrano 3 is to set up passwordless sudo.

like image 179
Oscar Barrett Avatar answered Nov 02 '22 05:11

Oscar Barrett