Cap 2.6 - Run as another user

37 views
Skip to first unread message

Gokulakrishnan Sarangaraju

unread,
Oct 18, 2016, 4:40:22 AM10/18/16
to Capistrano
Versions:
  • Ruby - 1.8.7
  • Capistrano - 2.6.0
  • Rake / Rails / etc
Platform:
  • Working on....CentOS
  • Deploying to... CentOS
Logs: 

Even though "deployuser" has the rights to switch to "admin" user without entering password, cap script is expecting password to be entered. 

-bash-4.1$ cap -f /tmp/captest-user.cap deploy
  * executing `deploy'
  * executing "whoami"
    servers: ["host1"]
    [host1] executing command
 ** [out :: host1] deployuser
    command finished in 69ms
  * executing "sudo -p 'sudo password: ' -u admin /data/myapplication/script.sh stop"
    servers: ["host1"]
    [host1] executing command
Password:


Files:
  • Capfile
    • default_run_options[:pty] = true
    • role :app, "host1"
    • task :deploy, roles => :app do
    • run "whoami"
    • run "/data/myapplication/script.sh stop", :shell => "sudo su - cmsadmin"
    • run "tail -f /home/apache-tomcat-7.0.67/logs/catalina.out | sed '/^INFO: Stopping ProtocolHandler/ q'"
    • run "sudo puppet agent --confdir=/home/puppet --waitforcert 60 --test; true"
    • end
In 2.6 is there a way i can execute commands on behalf of another user ("admin" in my case)? If so how? I understand that this is possible with the help of https://github.com/fundingcircle/sshkit-backends-netssh_global in Cap 3.0. But i would like to know if it is achievable using 2.6 or should i have to upgrade it? 

Any pointers will help me a lot. Thanks!

William Johnston

unread,
Oct 18, 2016, 8:31:31 AM10/18/16
to capis...@googlegroups.com
I'd suggest upgrading. You might be able to find people to help you
with this older version, but most people (IMO) have upgraded and will
be able to support Capistrano 3.

~William Johnston
> --
> You received this message because you are subscribed to the Google Groups
> "Capistrano" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to capistrano+...@googlegroups.com.
> To view this discussion on the web, visit
> https://groups.google.com/d/msgid/capistrano/71a57de7-0950-4f2d-9786-e89825e88972%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Gokulakrishnan Sarangaraju

unread,
Oct 18, 2016, 9:30:00 PM10/18/16
to Capistrano
Sure William. I will upgrade to 3.1 or to a latest version for future queries. 

btw i was able to solve that issue with by allowing commands to be executed while switching user (sudo su - admin -c "command here"). It has nothing to do with Capistrano version. 

Regards,
Gokul

William Johnston

unread,
Oct 18, 2016, 10:03:51 PM10/18/16
to capis...@googlegroups.com

I'm glad to hear you got it working! Thanks for reporting back.

~Willam


To unsubscribe from this group and stop receiving emails from it, send an email to capistrano+unsubscribe@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/capistrano/6d0877e3-41a4-44fb-9919-4de04e7a8037%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages