diff options
author | Vivek Singh <vivek.singh@msystechnologies.com> | 2019-08-14 13:25:04 +0530 |
---|---|---|
committer | Vivek Singh <vivek.singh@msystechnologies.com> | 2019-08-14 13:25:04 +0530 |
commit | 703ef2ac39833fd3883815eb77d4434dacade7ca (patch) | |
tree | f1ff77450d0b836dda8f5c01f857a599bb14f65c | |
parent | 9cdf03ee25d0349459474e33f42c64d68bd900e1 (diff) | |
download | chef-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>
-rw-r--r-- | lib/chef/knife/bootstrap.rb | 17 | ||||
-rw-r--r-- | spec/unit/knife/bootstrap_spec.rb | 5 |
2 files changed, 14 insertions, 8 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 diff --git a/spec/unit/knife/bootstrap_spec.rb b/spec/unit/knife/bootstrap_spec.rb index 5f4be8dfa2..2d5db2a98a 100644 --- a/spec/unit/knife/bootstrap_spec.rb +++ b/spec/unit/knife/bootstrap_spec.rb @@ -1021,7 +1021,6 @@ describe Chef::Knife::Bootstrap do verify_host_key: nil, port: 9999, non_interactive: true, - pty: true, } end @@ -1076,7 +1075,6 @@ describe Chef::Knife::Bootstrap do verify_host_key: nil, # Config port: 12, # cli non_interactive: true, - pty: true, } end @@ -1128,7 +1126,6 @@ describe Chef::Knife::Bootstrap do sudo_password: "blah", verify_host_key: true, non_interactive: true, - pty: true, } end it "generates a config hash using the CLI options and pulling nothing from Chef::Config" do @@ -1152,7 +1149,6 @@ describe Chef::Knife::Bootstrap do sudo: false, verify_host_key: "always", non_interactive: true, - pty: true, connection_timeout: 60, } end @@ -1504,7 +1500,6 @@ describe Chef::Knife::Bootstrap do let(:default_opts) do { non_interactive: true, - pty: true, forward_agent: false, connection_timeout: 60, } |