summaryrefslogtreecommitdiff
path: root/lib/chef/run_context/cookbook_compiler.rb
diff options
context:
space:
mode:
authorThom May <thom@chef.io>2017-04-05 11:49:51 +0100
committerThom May <thom@chef.io>2017-04-05 18:17:38 +0100
commit5c86ade466a38536186218009e32bb4db1ab3c92 (patch)
treed6e93d25ab4736a9d6f3c338971c56302c3f7708 /lib/chef/run_context/cookbook_compiler.rb
parenta9d0cfb3bcb995d60e096a755e4e58fa47f40047 (diff)
downloadchef-5c86ade466a38536186218009e32bb4db1ab3c92.tar.gz
RFC 59: Load Ohai pluginstm/ohai_plugins_2
This adds a new phase in the compilation of the run context. Signed-off-by: Thom May <thom@chef.io>
Diffstat (limited to 'lib/chef/run_context/cookbook_compiler.rb')
-rw-r--r--lib/chef/run_context/cookbook_compiler.rb35
1 files changed, 35 insertions, 0 deletions
diff --git a/lib/chef/run_context/cookbook_compiler.rb b/lib/chef/run_context/cookbook_compiler.rb
index 94635be03d..02ee2e3519 100644
--- a/lib/chef/run_context/cookbook_compiler.rb
+++ b/lib/chef/run_context/cookbook_compiler.rb
@@ -57,6 +57,7 @@ class Chef
# Run the compile phase of the chef run. Loads files in the following order:
# * Libraries
+ # * Ohai
# * Attributes
# * LWRPs
# * Resource Definitions
@@ -69,6 +70,7 @@ class Chef
# #cookbook_order for more information.
def compile
compile_libraries
+ compile_ohai_plugins
compile_attributes
compile_lwrps
compile_resource_definitions
@@ -101,6 +103,26 @@ class Chef
@events.library_load_complete
end
+ # Loads Ohai Plugins from cookbooks, and ensure any old ones are
+ # properly cleaned out
+ def compile_ohai_plugins
+ ohai_plugin_count = count_files_by_segment(:ohai)
+ @events.ohai_plugin_load_start(ohai_plugin_count)
+ FileUtils.rm_rf(Chef::Config[:ohai_segment_plugin_path])
+
+ cookbook_order.each do |cookbook|
+ load_ohai_plugins_from_cookbook(cookbook)
+ end
+
+ # Doing a full ohai system check is costly, so only do so if we've loaded additional plugins
+ if ohai_plugin_count > 0
+ ohai = Ohai::System.new.run_additional_plugins(Chef::Config[:ohai_segment_plugin_path])
+ node.consume_ohai_data(ohai)
+ end
+
+ @events.ohai_plugin_load_complete
+ end
+
# Loads attributes files from cookbooks. Attributes files are loaded
# according to #cookbook_order; within a cookbook, +default.rb+ is loaded
# first, then the remaining attributes files in lexical sort order.
@@ -226,6 +248,19 @@ class Chef
raise
end
+ def load_ohai_plugins_from_cookbook(cookbook_name)
+ target = Chef::Config[:ohai_segment_plugin_path]
+ files_in_cookbook_by_segment(cookbook_name, :ohai).each do |filename|
+ next unless File.extname(filename) == ".rb"
+
+ Chef::Log.debug "Loading Ohai plugin: #{filename} from #{cookbook_name}"
+ target_name = File.join(target, cookbook_name.to_s, File.basename(filename))
+
+ FileUtils.mkdir_p(File.dirname(target_name))
+ FileUtils.cp(filename, target_name)
+ end
+ end
+
def load_resource_definitions_from_cookbook(cookbook_name)
files_in_cookbook_by_segment(cookbook_name, :definitions).each do |filename|
begin