sshkit icon indicating copy to clipboard operation
sshkit copied to clipboard

An exit in parallel execution exits from all hosts

Open spurnaye opened this issue 8 years ago • 2 comments

I am using sshkit for parallel execution of commands on several servers. If there is an exit on one of the servers, then the exception is raised and execution on all the servers stops. As per the my requirements only that host should be skipped continuing other hosts. Can this be achieved with the current code?

Here is an example code

require 'sshkit'
require 'sshkit/dsl'
include SSHKit::DSL

hosts = ['[email protected]', '[email protected]', '[email protected]']

on hosts, in: :parallel do |host|
	execute './script.sh'
	execute './script_with_exit.sh'
end

spurnaye avatar Dec 27 '16 17:12 spurnaye

Hi, thanks for the question. You should also check on Stack Overflow to see if you get more answers there.

The requirement you describe is not possible with the current execution model of SSHKit, at least out of the box. You might be able to plug in your own custom runner to do this.

In other words, instead of this:

in: :parallel

You could write this:

in: ParallelIgnoringErrors

And define the runner as follows:

class ParallelIgnoringErrors < SSHKit::Runner::Abstract
  def execute
    # your custom execution logic goes here
  end
end

If you get it to work, let us know, and we can discuss whether this belongs in SSHKit and/or something that should be called out in the docs.

mattbrictson avatar Dec 27 '16 17:12 mattbrictson

Using test() rather than execute returns the result of the command rather than erring if it's non zero. test() is just a wrapper around execute() which sets certain flags on the command object (namely not to raise on exceptions) - depending on the nature of your failure this may or may not do what you want. See our examples file in the root of the project.

(Sent from my Nexus 6, please forgive typos!)

On Dec 27, 2016 18:53, "Matt Brictson" [email protected] wrote:

Hi, thanks for the question. You should also check on Stack Overflow to see if you get more answers there.

The requirement you describe is not possible with the current execution model of SSHKit, at least out of the box. You might be able to plug in your own custom runner to do this.

In other words, instead of this:

in: :parallel

You could write this:

in: ParallelIgnoringErrors

And define the runner as follows:

class ParallelIgnoringErrors < SSHKit::Runner::Abstract def execute # your custom execution logic goes here endend

If you get it to work, let us know, and we can discuss whether this belongs in SSHKit and/or something that should be called out in the docs.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/capistrano/sshkit/issues/384#issuecomment-269359452, or mute the thread https://github.com/notifications/unsubscribe-auth/AABKCBV7VhSbouyrlmTycQpMw94tIekqks5rMVCPgaJpZM4LWZyB .

leehambley avatar Dec 27 '16 18:12 leehambley