summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordheerajd-msys <dheeraj.dubey@msystechnologies.com>2020-03-17 16:03:58 +0530
committerTim Smith <tsmith84@gmail.com>2020-09-02 13:57:56 -0700
commit71e969a8340a3f331f16241dd6481379772b7942 (patch)
tree943d30d062c22f02997fdfd1c0ba8e8a3adf33b7
parent327997a13b5f273f34a319e2e7b6aa2abd877f11 (diff)
downloadchef-71e969a8340a3f331f16241dd6481379772b7942.tar.gz
remove --ssh-pty with update
Signed-off-by: dheerajd-msys <dheeraj.dubey@msystechnologies.com>
-rw-r--r--lib/chef/knife/ssh.rb24
1 files changed, 13 insertions, 11 deletions
diff --git a/lib/chef/knife/ssh.rb b/lib/chef/knife/ssh.rb
index 41d002cbd6..e1dbf8446a 100644
--- a/lib/chef/knife/ssh.rb
+++ b/lib/chef/knife/ssh.rb
@@ -134,12 +134,6 @@ class Chef
boolean: true,
default: false
- option :ssh_pty,
- long: "--ssh-pty",
- description: "PTY flag. Provide this option if PTY is configured on node.",
- boolean: true,
- default: false
-
def session
ssh_error_handler = Proc.new do |server|
if config[:on_error]
@@ -368,15 +362,17 @@ class Chef
subsession ||= session
command = fixup_sudo(command)
command.force_encoding("binary") if command.respond_to?(:force_encoding)
+ open_session(subsession, command)
+ end
+
+ def open_session(subsession, command, pty = false)
+ stderr = ""
+ exit_status = 0
subsession.open_channel do |chan|
if config[:on_error] && exit_status != 0
chan.close
else
- if config[:ssh_pty]
- chan.request_pty do |ch, success|
- raise Train::Transports::SSHPTYFailed, "Requesting PTY failed" unless success
- end
- end
+ chan.request_pty if pty
chan.exec command do |ch, success|
raise ArgumentError, "Cannot execute #{command}" unless success
@@ -387,8 +383,14 @@ class Chef
ichannel.send_data("#{get_password}\n")
end
end
+
+ ch.on_extended_data do |_, _type, data|
+ stderr += data
+ end
+
ch.on_request "exit-status" do |ichannel, data|
exit_status = [exit_status, data.read_long].max
+ exit_status = open_session(subsession, command, true) if exit_status != 0 && stderr.include?("sudo: sorry, you must have a tty to run sudo")
end
end
end