diff options
author | Lamont Granquist <lamont@scriptkiddie.org> | 2021-07-09 12:44:35 -0700 |
---|---|---|
committer | Lamont Granquist <lamont@scriptkiddie.org> | 2021-07-09 12:44:35 -0700 |
commit | 9d7a164a9d8798896457a23112af1c779bde5dcd (patch) | |
tree | d6e12de5b4c0e98e587660321edecb2b2972e7ea | |
parent | a8caffdb0ff9ac5971cd7a4424b12205b621314d (diff) | |
download | chef-9d7a164a9d8798896457a23112af1c779bde5dcd.tar.gz |
Add --pty option, rename the "subsession" argument
Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
-rw-r--r-- | knife/lib/chef/knife/ssh.rb | 31 |
1 files changed, 20 insertions, 11 deletions
diff --git a/knife/lib/chef/knife/ssh.rb b/knife/lib/chef/knife/ssh.rb index 034fdc48b5..b474696d02 100644 --- a/knife/lib/chef/knife/ssh.rb +++ b/knife/lib/chef/knife/ssh.rb @@ -134,12 +134,18 @@ class Chef boolean: true, default: false - option :require_pty, - long: "--[no-]require-pty", + option :pty, + long: "--[no-]pty", description: "Request a PTY, enabled by default.", boolean: true, default: true + option :require_pty, + long: "--[no-]require-pty", + description: "Raise exception if a PTY cannot be acquired, disabled by default.", + boolean: true, + default: false + def session ssh_error_handler = Proc.new do |server| if config[:on_error] @@ -359,21 +365,24 @@ class Chef ui.msg(str) end - def ssh_command(command, subsession = nil) + # @param command [String] the command to run + # @param session_list [???] list of sessions, one per node + # + def ssh_command(command, session_list = session) stderr = "" exit_status = 0 - subsession ||= session command = fixup_sudo(command) command.force_encoding("binary") if command.respond_to?(:force_encoding) - subsession.open_channel do |chan| + session_list.open_channel do |chan| if config[:on_error] && exit_status != 0 chan.close else - 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] - + if config[:pty] + 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 end chan.exec command do |ch, success| @@ -400,7 +409,7 @@ class Chef session.loop exit_status ensure - subsession.close + session_list.close end def get_password |