summaryrefslogtreecommitdiff
path: root/lib/chef/knife
diff options
context:
space:
mode:
authorVivek Singh <vivek.singh@msystechnologies.com>2019-08-14 13:25:04 +0530
committerVivek Singh <vivek.singh@msystechnologies.com>2019-08-14 13:25:04 +0530
commit703ef2ac39833fd3883815eb77d4434dacade7ca (patch)
treef1ff77450d0b836dda8f5c01f857a599bb14f65c /lib/chef/knife
parent9cdf03ee25d0349459474e33f42c64d68bd900e1 (diff)
downloadchef-703ef2ac39833fd3883815eb77d4434dacade7ca.tar.gz
Bootstrap: Set pty true only if required
- rescue the exception and retry with pty: true if host configured with `requiretty`. - Remove the default pty: true for all node that causes the error in the window and other hosts while detecting the system. Signed-off-by: Vivek Singh <vivek.singh@msystechnologies.com>
Diffstat (limited to 'lib/chef/knife')
-rw-r--r--lib/chef/knife/bootstrap.rb17
1 files changed, 14 insertions, 3 deletions
diff --git a/lib/chef/knife/bootstrap.rb b/lib/chef/knife/bootstrap.rb
index e892f1f2c9..8ded1451ef 100644
--- a/lib/chef/knife/bootstrap.rb
+++ b/lib/chef/knife/bootstrap.rb
@@ -670,8 +670,20 @@ class Chef
end
def do_connect(conn_options)
- @connection = TrainConnector.new(host_descriptor, connection_protocol, conn_options)
- connection.connect!
+ retry_require = true
+ begin
+ @connection = TrainConnector.new(host_descriptor, connection_protocol, conn_options)
+ connection.connect!
+ rescue Train::UserError => e
+ if retry_require && e.message =~ /Sudo requires a TTY/
+ ui.warn("#{e.message} - trying with pty request")
+ retry_require = false
+ conn_options[:pty] = true # ensure we can talk to systems with requiretty set true in sshd config
+ retry
+ else
+ raise
+ end
+ end
end
# Fail if both first_boot_attributes and first_boot_attributes_from_file
@@ -895,7 +907,6 @@ class Chef
opts = {}
return opts if winrm?
- opts[:pty] = true # ensure we can talk to systems with requiretty set true in sshd config
opts[:non_interactive] = true # Prevent password prompts from underlying net/ssh
opts[:forward_agent] = (config_value(:ssh_forward_agent) === true)
opts[:connection_timeout] = session_timeout