summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgscho <greg.c.schofield@gmail.com>2021-05-10 09:44:43 -0400
committergscho <greg.c.schofield@gmail.com>2021-05-10 09:45:59 -0400
commit03db5e4bb71ec401fc72ab4f32fb9659c7d65b80 (patch)
tree14f4af21d0e91502b169650a827b73025a483d2d
parentef81cbcec7ce4bb6c216ddc2d7b7196a0475a92c (diff)
downloadchef-03db5e4bb71ec401fc72ab4f32fb9659c7d65b80.tar.gz
Rename flag and only raise when PTY required
Signed-off-by: gscho <greg.c.schofield@gmail.com>
-rw-r--r--knife/lib/chef/knife/ssh.rb24
1 files changed, 9 insertions, 15 deletions
diff --git a/knife/lib/chef/knife/ssh.rb b/knife/lib/chef/knife/ssh.rb
index e6268627c2..034fdc48b5 100644
--- a/knife/lib/chef/knife/ssh.rb
+++ b/knife/lib/chef/knife/ssh.rb
@@ -134,8 +134,8 @@ class Chef
boolean: true,
default: false
- option :ssh_pty,
- long: "--[no-]ssh-pty",
+ option :require_pty,
+ long: "--[no-]require-pty",
description: "Request a PTY, enabled by default.",
boolean: true,
default: true
@@ -360,26 +360,22 @@ class Chef
end
def ssh_command(command, subsession = nil)
+ stderr = ""
exit_status = 0
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)
- 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|
- ui.error("Requesting PTY failed. If a PTY is not required use --no-ssh-pty") unless success
+ chan.request_pty do |ch, success|
+ unless success
+ ui.warn("Failed to obtain a PTY from #{ch.connection.host}")
+ raise ArgumentError, "Request for PTY failed" if config[:require_pty]
+
end
end
-
chan.exec command do |ch, success|
raise ArgumentError, "Cannot execute #{command}" unless success
@@ -390,13 +386,11 @@ class Chef
ichannel.send_data("#{get_password}\n")
end
end
-
ch.on_extended_data do |_, _type, data|
- ui.error("No PTY present. If a PTY is required use --ssh-pty") if data.eql?("sudo: no tty present and no askpass program specified\n")
+ raise ArgumentError, "No PTY present. If a PTY is required use --require-pty" if data.eql?("sudo: no tty present and no askpass program specified\n")
stderr += data
end
-
ch.on_request "exit-status" do |ichannel, data|
exit_status = [exit_status, data.read_long].max
end