How to strictly display commands but not run them in Capistrano?

48 views
Skip to first unread message

Haani Niyaz

unread,
Oct 20, 2014, 2:54:47 AM10/20/14
to capis...@googlegroups.com
Hi There,

I am attempted to have Capistrano tasks only display the commands instead of executing them. I did this by basically using a function which determines if the command needs to be executed or printed based on a 'debug' flag passed as an argument which would be accessed as a environment variable,  however I encountered some exceptions:

What I've done:

def execute_as cmd

   
if $debug.eql? 'true'
        puts cmd
   
else
        execute
"#{cmd}"
   
end


The above works fine for all except for the following scenario:

# fails for any test command
if test(" [ ! -d /usr/backup ] ")
                    puts
"+ Creating backup point /usr/backup.."
                    execute_as
"sudo mkdir /usr/backup"
                    puts
"#{$checkmark} Created /usr/backup"
               
end


The exception below is:
1. Only generated when it encounters the first test command.
2. Does not terminate. Prints all command successfully until the end.


DEBUG
[ba34641c] Command: [ ! -d /usr/backup ]
Exception `Net::SSH::Exception' at /opt/ruby/ruby-2.0.0-p451/usr/lib64/ruby/gems/2.0.0/gems/net-ssh-2.9.1/lib/net/ssh/transport/algorithms.rb:329 - could not settle on language_client algorithm
Exception `
Net::SSH::Exception' at /opt/ruby/ruby-2.0.0-p451/usr/lib64/ruby/gems/2.0.0/gems/net-ssh-2.9.1/lib/net/ssh/transport/algorithms.rb:329 - could not settle on language_server algorithm
Exception `Net::SSH::Authentication::DisallowedMethod'
at /opt/ruby/ruby-2.0.0-p451/usr/lib64/ruby/gems/2.0.0/gems/net-ssh-2.9.1/lib/net/ssh/authentication/methods/none.rb:23 - Net::SSH::Authentication::DisallowedMethod
Exception `TypeError' at /opt/ruby/ruby-2.0.0-p451/usr/lib64/ruby/gems/2.0.0/gems/net-ssh-2.9.1/lib/net/ssh/authentication/agent/socket.rb:65 - no implicit conversion of nil into String
Exception `
Net::SSH::Authentication::AgentNotAvailable' at /opt/ruby/ruby-2.0.0-p451/usr/lib64/ruby/gems/2.0.0/gems/net-ssh-2.9.1/lib/net/ssh/authentication/agent/socket.rb:68 - no implicit conversion of nil into String


I can SSH into the remote server successfully and if the debug option is off, no exceptions are generated.

A closer look led me to change the environment variable name (instead of using 'debug') which solved the problem.

I was hoping someone could explain this behavior? 
Thanks.


Versions:
  • Ruby 1.8.7
  • Capistrano 3

Haani Niyaz

unread,
Oct 20, 2014, 2:55:30 AM10/20/14
to capis...@googlegroups.com
I was also curious to know if there was a better way to do this? cheers.

Lee Hambley

unread,
Oct 20, 2014, 3:56:57 AM10/20/14
to capistrano
You won't be able to pass any test() command by just printing, since test relies on the answer from the upstream server to determine which way the Ruby code should branch.

--
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/0a9b03b2-6e54-477d-9599-1d8163afb43e%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Haani Niyaz

unread,
Oct 20, 2014, 4:56:51 AM10/20/14
to capis...@googlegroups.com
Oh yeah definitely but because the test() command (in my implementation) doesn't make any system/application changes I leave it as is.
Reply all
Reply to author
Forward
0 new messages