I made a small test task below:
set :user, "user"
set :password, "password"
set :root_password, "root password"
set :use_sudo, false
role :srv, "exmaple.com"
task :show_info do
run "iptables -L", :shell => "su -" do |channel, stream, data|
channel.send_data("#{root_password}\n")
end
end
This server doesn't allow me to use sudo
, so I have to login as a normal user then become root.
I have also tried to create surun
from this article, though it doesn't help me... :(
Could someone please tell me the promising method to run command after switching to root in Capistrano?
Thanks in advance.
P.S. Added the output log:
$ cap show_info
* executing `show_info'
* executing "iptables -L"
servers: ["example.com"]
[example.com] executing command
command finished in 000ms
failed: "su - -c 'iptables -L'" on example.com
The point is default_run_options[:pty] = true
try this