Continuous user switching in Capistrano 3 (separate authorization and deployment)

We have the following template in server management - all users have their own user, but the deployment is completely performed by a special deployment user without direct login.

We used this method in Capistrano 2.x:

default_run_options[:shell] = "sudo -u deploy bash" $ cap stage deploy -s user=thisisme 

I know that Capistrano 3.x has a way to directly switch the user:

 task :install do on roles(:all) do as :deploy do execute :whoami end end end 

But this code will populate all tasks, and tasks by default will not inherit the deployment user. Is it possible to immediately configure the login user without dragging this code for each task?

+8
ruby deployment capistrano
source share
1 answer

Since I did not receive any correct answer and did not understand myself, I decided to ask the authors. Capistrano 3.x uses SSHKit to manage remote execution commands, and here is their answer :

You can try redefining the command map so that each command has a prefix for the desired sudo line. https://github.com/capistrano/sshkit/blob/master/README.md#the-command-map

 SSHKit.config.command_map = Hash.new do |hash, command| hash[command] = "<<sudo stuff goes here>> #{command}" end 

The documentation says: "It may be unreasonable, but it would be possible." Ymmv

+6
source share

All Articles