summaryrefslogtreecommitdiff
path: root/lib/chef/run_context
diff options
context:
space:
mode:
authorThom May <thom@may.lt>2017-04-05 18:56:25 +0100
committerGitHub <noreply@github.com>2017-04-05 18:56:25 +0100
commite75454384a9763458ea7d6d0aa7472521025dcbd (patch)
tree36d573ddd3538f543e26a10220a82dd7e44ecec2 /lib/chef/run_context
parent35c01678e56877ca374fdbee3bbe31c122f3f930 (diff)
parent5c86ade466a38536186218009e32bb4db1ab3c92 (diff)
downloadchef-e75454384a9763458ea7d6d0aa7472521025dcbd.tar.gz
Merge pull request #6017 from chef/tm/ohai_plugins_2
RFC 59 - Load ohai plugins
Diffstat (limited to 'lib/chef/run_context')
-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 ea5931ac75..f2598a4f27 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.
@@ -235,6 +257,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