Capistrano 3 sudo task

crimi picture crimi · Nov 13, 2013 · Viewed 26.1k times · Source

I want to write a recipe with Capistrano 3 executing a task on the remote server with sudo.

With Capistrano 2 this could be done for example:

default_run_options[:pty] = true

task :hello do
  run "#{sudo} cp ~/something /something"
end

With Capistrano 3 I found:

set :pty, true

But I could not get to execute a task running with sudo.

How can I run a task with sudo?

Answer

Ian picture Ian · Nov 19, 2013

The Capistrano 3 guide recommends the use of passwordless sudo. This allows your less-priveleged user execute the sudo command without having to enter a password via the PTY.

You can use the task that Kentaro wrote above, and add something like the following to your /etc/sudoers file:

deploy ALL=NOPASSWD:/bin/cp ~/something /something

http://www.capistranorb.com/documentation/getting-started/authentication-and-authorisation/#toc_8