summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2020-10-14 11:43:38 -0700
committerLamont Granquist <lamont@scriptkiddie.org>2020-10-14 11:43:38 -0700
commit6d351c90b22f804f5cbc00c43a10ca464397fbbd (patch)
tree9a49907ed38d96d090b9c8d235a78b790af47306
parent7ea5d629ed94da45ef41f98f102fb0bb7da95749 (diff)
downloadchef-6d351c90b22f804f5cbc00c43a10ca464397fbbd.tar.gz
Remote ohai support for chef-client
This replaces the existing hacked up platform detection via inspec that was added to chef-client with proper support from ohai. Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
-rw-r--r--lib/chef/application/client.rb7
-rw-r--r--lib/chef/client.rb33
2 files changed, 8 insertions, 32 deletions
diff --git a/lib/chef/application/client.rb b/lib/chef/application/client.rb
index 4a749a7c39..39ae7adaac 100644
--- a/lib/chef/application/client.rb
+++ b/lib/chef/application/client.rb
@@ -27,6 +27,7 @@ module Mixlib
autoload :Log, "mixlib/authentication"
end
end
+autoload :Train, "train"
# DO NOT MAKE EDITS, see Chef::Application::Base
#
@@ -115,8 +116,12 @@ class Chef::Application::Client < Chef::Application::Base
Chef::Config.chef_zero.port = config[:chef_zero_port] if config[:chef_zero_port]
if config[:target] || Chef::Config.target
- Chef::Config.target_mode.enabled = true
Chef::Config.target_mode.host = config[:target] || Chef::Config.target
+ if URI.parse(Chef::Config.target_mode.host).scheme
+ train_config = Train.unpack_target_from_uri(Chef::Config.target_mode.host)
+ Chef::Config.target_mode = train_config
+ end
+ Chef::Config.target_mode.enabled = true
Chef::Config.node_name = Chef::Config.target_mode.host unless Chef::Config.node_name
end
diff --git a/lib/chef/client.rb b/lib/chef/client.rb
index 04d907634b..41e3846812 100644
--- a/lib/chef/client.rb
+++ b/lib/chef/client.rb
@@ -251,11 +251,7 @@ class Chef
logger.debug("#{ChefUtils::Dist::Infra::CLIENT.capitalize} request_id: #{request_id}")
ENV["PATH"] = ChefUtils::DSL::DefaultPaths.default_paths if Chef::Config[:enforce_default_paths] || Chef::Config[:enforce_path_sanity]
- if Chef::Config.target_mode?
- get_ohai_data_remotely
- else
- run_ohai
- end
+ run_ohai
unless Chef::Config[:solo_legacy_mode]
register
@@ -576,32 +572,6 @@ class Chef
end
#
- # Populate the minimal ohai attributes defined in #run_ohai with data train collects.
- #
- # Eventually ohai may support colleciton of data.
- #
- def get_ohai_data_remotely
- ohai.data[:fqdn] = if transport_connection.respond_to?(:hostname)
- transport_connection.hostname
- else
- Chef::Config[:target_mode][:host]
- end
- if transport_connection.respond_to?(:os)
- ohai.data[:platform] = transport_connection.os.name
- ohai.data[:platform_version] = transport_connection.os.release
- ohai.data[:os] = transport_connection.os.family_hierarchy[1]
- ohai.data[:platform_family] = transport_connection.os.family
- end
- # train does not collect these specifically
- # ohai.data[:machinename] = nil
- # ohai.data[:hostname] = nil
- # ohai.data[:os_version] = nil # kernel version
-
- ohai.data[:ohai_time] = Time.now.to_f
- events.ohai_completed(node)
- end
-
- #
# Run ohai plugins. Runs all ohai plugins unless minimal_ohai is specified.
#
# Sends the ohai_completed event when finished.
@@ -613,6 +583,7 @@ class Chef
#
def run_ohai
filter = Chef::Config[:minimal_ohai] ? %w{fqdn machinename hostname platform platform_version ohai_time os os_version init_package} : nil
+ ohai.transport_connection = transport_connection if Chef::Config.target_mode?
ohai.all_plugins(filter)
events.ohai_completed(node)
end