Skip to content

Commit

Permalink
[COOK-463] ohai cookbook default recipe should only reload plugins if…
Browse files Browse the repository at this point in the history
… there were updates
  • Loading branch information
schisamo committed Jun 30, 2011
1 parent 6929b9b commit c641296
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
14 changes: 10 additions & 4 deletions ohai/README.md
@@ -1,14 +1,14 @@
Description
===========

Creates a configured plugin path for distributing custom Ohai plugins, and reloads them via Ohai within the context of a Chef Client run during the compile phase.
Creates a configured plugin path for distributing custom Ohai plugins, and reloads them via Ohai within the context of a Chef Client run during the compile phase (if needed).

Attributes
==========

`node[:ohai][:plugin_path]` - location to drop off plugins directory, default is `/etc/chef/ohai_plugins`. This is not FHS-compliant, an FHS location would be something like `/var/lib/ohai/plugins`, or `/var/lib/chef/ohai_plugins` or similar.
`node['ohai']['plugin_path']` - location to drop off plugins directory, default is `/etc/chef/ohai_plugins`. This is not FHS-compliant, an FHS location would be something like `/var/lib/ohai/plugins`, or `/var/lib/chef/ohai_plugins` or similar.

Neither an FHS location or the default value of this attribute are in the default Ohai plugin path. Set the Ohai plugin path with the config setting "`Ohai::Config[:plugin_path`" in the Chef config file. The attribute is not set to the default plugin path that Ohai ships with because we don't want to risk destroying existing essential plugins for Ohai.
Neither an FHS location or the default value of this attribute are in the default Ohai plugin path. Set the Ohai plugin path with the config setting "`Ohai::Config[:plugin_path]`" in the Chef config file (the `chef::config` recipe does this automatically for you!). The attribute is not set to the default plugin path that Ohai ships with because we don't want to risk destroying existing essential plugins for Ohai.

Usage
=====
Expand All @@ -21,12 +21,18 @@ For information on how to write custom plugins for Ohai, please see the Chef wik

http://wiki.opscode.com/display/chef/Writing+Ohai+Plugins

*PLEASE NOTE* - This recipe reloads the Ohai plugins a 2nd time during the Chef run if:

* The "`Ohai::Config[:plugin_path]`" config setting has *NOT* been properly set in the Chef config file
* The "`Ohai::Config[:plugin_path]`" config setting has been properly set in the Chef config file and there are updated plugins dropped off at "`node['ohai']['plugin_path']`".

License and Author
==================

Author:: Joshua Timberman (<joshua@opscode.com>)
Author:: Seth Chisamore (<schisamo@opscode.com>)

Copyright:: 2010, Opscode, Inc
Copyright:: 2011, Opscode, Inc

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
26 changes: 12 additions & 14 deletions ohai/recipes/default.rb
Expand Up @@ -2,7 +2,7 @@
# Cookbook Name:: ohai
# Recipe:: default
#
# Copyright 2010, Opscode, Inc
# Copyright 2011, Opscode, Inc
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -20,26 +20,24 @@
Ohai::Config[:plugin_path] << node['ohai']['plugin_path']
Chef::Log.info("ohai plugins will be at: #{node['ohai']['plugin_path']}")

d = directory node['ohai']['plugin_path'] do
owner 'root'
group 'root'
mode 0755
recursive true
action :nothing
end

d.run_action(:create)

rd = remote_directory node['ohai']['plugin_path'] do
source 'plugins'
owner 'root'
group 'root'
mode 0755
recursive true
action :nothing
end

rd.run_action(:create)

o = Ohai::System.new
o.all_plugins
node.automatic_attrs.merge! o.data
# only reload ohai if new plugins were dropped off OR
# node['ohai']['plugin_path'] does not exists in client.rb
if rd.updated? ||
!(::IO.read(Chef::Config[:config_file]) =~ /Ohai::Config\[:plugin_path\]\s*<<\s*["']#{node['ohai']['plugin_path']}["']/)

ohai 'custom_plugins' do
action :nothing
end.run_action(:reload)

end

0 comments on commit c641296

Please sign in to comment.