summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteven Murawski <steven.murawski@gmail.com>2017-04-04 13:10:51 -0500
committerGitHub <noreply@github.com>2017-04-04 13:10:51 -0500
commit373a4514806ae33c08fd6afd205a661cc6a18e19 (patch)
treef0c7d135bf75c25273033c2fed67da096933fddd
parent93c72873224c6a79ae13b5d2fa70cb9bfc645c5c (diff)
parent48cd7479d35fc6789dcf9c9002102ac7c6a0170c (diff)
downloadchef-373a4514806ae33c08fd6afd205a661cc6a18e19.tar.gz
Merge pull request #5978 from Oxalide/fix-exit-on-error
fix knife ssh --exit-on-error
-rw-r--r--lib/chef/knife/ssh.rb26
1 files changed, 15 insertions, 11 deletions
diff --git a/lib/chef/knife/ssh.rb b/lib/chef/knife/ssh.rb
index f048c7268d..380a60fdd6 100644
--- a/lib/chef/knife/ssh.rb
+++ b/lib/chef/knife/ssh.rb
@@ -331,18 +331,22 @@ class Chef
command = fixup_sudo(command)
command.force_encoding("binary") if command.respond_to?(:force_encoding)
subsession.open_channel do |chan|
- chan.request_pty
- chan.exec command do |ch, success|
- raise ArgumentError, "Cannot execute #{command}" unless success
- ch.on_data do |ichannel, data|
- print_data(ichannel[:host], data)
- if data =~ /^knife sudo password: /
- print_data(ichannel[:host], "\n")
- ichannel.send_data("#{get_password}\n")
+ if config[:on_error] && exit_status != 0
+ chan.close()
+ else
+ chan.request_pty
+ chan.exec command do |ch, success|
+ raise ArgumentError, "Cannot execute #{command}" unless success
+ ch.on_data do |ichannel, data|
+ print_data(ichannel[:host], data)
+ if data =~ /^knife sudo password: /
+ print_data(ichannel[:host], "\n")
+ ichannel.send_data("#{get_password}\n")
+ end
+ end
+ ch.on_request "exit-status" do |ichannel, data|
+ exit_status = [exit_status, data.read_long].max
end
- end
- ch.on_request "exit-status" do |ichannel, data|
- exit_status = [exit_status, data.read_long].max
end
end
end