diff options
author | Vivek Singh <vivek.singh@msystechnologies.com> | 2020-04-09 03:17:40 +0530 |
---|---|---|
committer | Vivek Singh <vivek.singh@msystechnologies.com> | 2020-04-09 03:24:46 +0530 |
commit | 19fa0835e9540e7d93dcd2ca57f38f1a78a5ed92 (patch) | |
tree | 74e63d43b3d2c8e97264d0eee25832cf633c8775 /lib/chef | |
parent | 8b7e30a57a726539dfc0e493913eee464597b8fd (diff) | |
download | chef-19fa0835e9540e7d93dcd2ca57f38f1a78a5ed92.tar.gz |
Fixes for sudo password
Signed-off-by: Vivek Singh <vivek.singh@msystechnologies.com>
Diffstat (limited to 'lib/chef')
-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 82fa5971b8..b1b0c1ceeb 100644 --- a/lib/chef/knife/bootstrap.rb +++ b/lib/chef/knife/bootstrap.rb @@ -651,7 +651,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 @@ -667,7 +667,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 @@ -696,10 +696,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 |