summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaxime de Roucy <maxime.deroucy@oxalide.com>2017-03-31 15:53:00 +0200
committerMaxime de Roucy <maxime.deroucy@oxalide.com>2017-03-31 16:17:34 +0200
commit48cd7479d35fc6789dcf9c9002102ac7c6a0170c (patch)
treeaa7232c33639afc9f11eb8ccc98a3774290bc429
parent7a1a19a14942636a2dd7ff17a64f44250dd3980e (diff)
downloadchef-48cd7479d35fc6789dcf9c9002102ac7c6a0170c.tar.gz
fix knife ssh --exit-on-error
Signed-off-by: Maxime de Roucy <maxime.deroucy@oxalide.com>
-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 d79565991f..525d1a3de1 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