diff options
author | Tim Smith <tsmith@chef.io> | 2020-04-13 11:35:05 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-13 11:35:05 -0700 |
commit | b052f77af13ddca46f59f44a74bcce59aeda1a14 (patch) | |
tree | 922d3d54e28030fe35b4f965bfd1db88ecb440eb /lib/chef/knife/bootstrap.rb | |
parent | 7e6796e749a9be9b8255e73058be43aa1a501920 (diff) | |
parent | e9e76f6396281ec281365971d8e55e6cb35dcd07 (diff) | |
download | chef-b052f77af13ddca46f59f44a74bcce59aeda1a14.tar.gz |
Merge pull request #9635 from chef/VSingh/fix-sudo-password-error
Fixes for sudo password prompt
Diffstat (limited to 'lib/chef/knife/bootstrap.rb')
-rw-r--r-- | lib/chef/knife/bootstrap.rb | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/lib/chef/knife/bootstrap.rb b/lib/chef/knife/bootstrap.rb index 3785fa9c17..3ab7773e21 100644 --- a/lib/chef/knife/bootstrap.rb +++ b/lib/chef/knife/bootstrap.rb @@ -650,7 +650,7 @@ class Chef raise else ui.warn("Failed to authenticate #{opts[:user]} to #{server_name} - trying password auth") - password = ui.ask("Enter password for #{opts[:user]}@#{server_name}.") do |q| + password = ui.ask("Enter password for #{opts[:user]}@#{server_name}:") do |q| q.echo = false end end @@ -666,7 +666,7 @@ class Chef raise else ui.warn("Failed to authenticate #{opts[:user]} to #{server_name} - trying password auth") - password = ui.ask("Enter password for #{opts[:user]}@#{server_name}.") do |q| + password = ui.ask("Enter password for #{opts[:user]}@#{server_name}:") do |q| q.echo = false end end @@ -695,10 +695,20 @@ class Chef @connection = TrainConnector.new(host_descriptor, connection_protocol, conn_options) connection.connect! rescue Train::UserError => e + limit ||= 1 if !conn_options.key?(:pty) && e.reason == :sudo_no_tty ui.warn("#{e.message} - trying with pty request") conn_options[:pty] = true # ensure we can talk to systems with requiretty set true in sshd config retry + elsif config[:use_sudo_password] && (e.reason == :sudo_password_required || e.reason == :bad_sudo_password) && limit < 3 + ui.warn("Failed to authenticate #{conn_options[:user]} to #{server_name} - #{e.message} \n sudo: #{limit} incorrect password attempt") + sudo_password = ui.ask("Enter sudo password for #{conn_options[:user]}@#{server_name}:") do |q| + q.echo = false + end + limit += 1 + conn_options[:sudo_password] = sudo_password + + retry else raise end |