Question

I have the following deploy.rb with my capistrano-enabled project:

# config valid only for Capistrano 3.1
lock '3.1.0'

# Default value for :pty is false
# forward password prompts
set :pty, true

set :use_sudo, false

namespace :setup do

  desc 'installs required libraries'
  task :libraries do

    on roles(:app), in: :sequence do
      execute :sudo, 'whoami'
      execute :sudo, "apt-get install mplayer"
    end
  end
end

I might not really grasp the concept of :use_sudo and the execute :sudo, 'command' part but curiously the whoami returns root, even though :use_sudo is turned off.

The Documentation of v.2 states this too:

set :use_sudo, false. By default, Capistrano will try to use sudo to do certain operations (setting up your servers, restarting your application, etc.). If you are on a shared host, sudo might be unavailable to you, or maybe you just want to avoid using sudo.

So what is the :use_sudo flag for if sudo is executed anyways.

Was it helpful?

Solution

You're explicitly running a command in sudo: execute :sudo, 'whoami', why are you surprised that it uses sudo?

As explained in the documentation that you quoted, setting the :use_sudo option to false will tell Capistrano not to use sudo when doing certain operations. If you execute sudo whoami though it's not going to modify your command.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top