diff options
author | Vivek Singh <vivek.singh@msystechnologies.com> | 2020-04-09 03:17:40 +0530 |
---|---|---|
committer | Tim Smith <tsmith84@gmail.com> | 2020-04-15 19:53:46 -0700 |
commit | 5f649bf78d7bbfab0ae0829513a49ebd8aeac2e0 (patch) | |
tree | 0aa9b60e5f81cafcd9de19cf7272b0b45de98cb7 | |
parent | 40e92b52ac0e274433d139723846fca4847b9ed6 (diff) | |
download | chef-5f649bf78d7bbfab0ae0829513a49ebd8aeac2e0.tar.gz |
Fixes for sudo password
Signed-off-by: Vivek Singh <vivek.singh@msystechnologies.com>
-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 9e2c66a782..d8668bc070 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 == :sudo_root_password_required) && 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 root 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 |