summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordheerajd-msys <dheeraj.dubey@msystechnologies.com>2020-03-17 16:03:58 +0530
committerdheerajd-msys <dheeraj.dubey@msystechnologies.com>2020-08-19 18:52:37 +0530
commit21f975163cf041af0f132a30ad3525e2e727d2a2 (patch)
tree8d2ed52aa5601a1aff688cfe552372055f55d756
parent506876bf5b3cafb015ad9e22a62b76af5021b6e9 (diff)
downloadchef-21f975163cf041af0f132a30ad3525e2e727d2a2.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 b40f845dbd..f7df0f788f 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]
@@ -364,15 +358,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
@@ -383,8 +379,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