summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgscho <greg.c.schofield@gmail.com>2021-04-22 15:08:44 -0400
committergscho <greg.c.schofield@gmail.com>2021-04-22 15:38:01 -0400
commitef81cbcec7ce4bb6c216ddc2d7b7196a0475a92c (patch)
tree74de931facdace1ed4adc0a4a1b8da6ad6a1aaa1
parent4fbc73901f0c7a19b0d16c879b8d6cb25210d5d1 (diff)
downloadchef-ef81cbcec7ce4bb6c216ddc2d7b7196a0475a92c.tar.gz
Add a flag to allow the user to request a pty
Signed-off-by: gscho <greg.c.schofield@gmail.com>
-rw-r--r--knife/lib/chef/knife/ssh.rb23
1 files changed, 15 insertions, 8 deletions
diff --git a/knife/lib/chef/knife/ssh.rb b/knife/lib/chef/knife/ssh.rb
index bac88b7d50..e6268627c2 100644
--- a/knife/lib/chef/knife/ssh.rb
+++ b/knife/lib/chef/knife/ssh.rb
@@ -134,6 +134,12 @@ class Chef
boolean: true,
default: false
+ option :ssh_pty,
+ long: "--[no-]ssh-pty",
+ description: "Request a PTY, enabled by default.",
+ boolean: true,
+ default: true
+
def session
ssh_error_handler = Proc.new do |server|
if config[:on_error]
@@ -358,21 +364,22 @@ class Chef
subsession ||= session
command = fixup_sudo(command)
command.force_encoding("binary") if command.respond_to?(:force_encoding)
- begin
- open_session(subsession, command)
- rescue => e
- open_session(subsession, command, true)
- end
+ open_session(subsession, command)
end
- def open_session(subsession, command, pty = false)
+ def open_session(subsession, command)
stderr = ""
exit_status = 0
subsession.open_channel do |chan|
if config[:on_error] && exit_status != 0
chan.close
else
- chan.request_pty if pty
+ 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
+ end
+ end
+
chan.exec command do |ch, success|
raise ArgumentError, "Cannot execute #{command}" unless success
@@ -385,7 +392,7 @@ class Chef
end
ch.on_extended_data do |_, _type, data|
- raise ArgumentError if data.eql?("sudo: no tty present and no askpass program specified\n")
+ 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")
stderr += data
end