Initial Chef repository

This commit is contained in:
Greg Karékinian
2015-07-21 19:45:23 +02:00
parent 7e5401fc71
commit ee4079fa85
1151 changed files with 185163 additions and 0 deletions

View File

@@ -0,0 +1,51 @@
ohai Cookbook CHANGELOG
=======================
This file is used to list changes made in each version of the ohai cookbook.
v2.0.1 (2014-06-07)
-------------------
* [COOK-4683] Remove warnings about reopening resource
Please note, this changes the name of a remote_directory resource. It is not expected that anyone would be explicitly notifying this resource but, please review [PR #16](https://github.com/opscode-cookbooks/ohai/pull/16/files) for more info.
v2.0.0 (2014-02-25)
-------------------
'[COOK-3865] - create lwrp ohai_hint'
v1.1.12
-------
- Dummy release due to a Community Site upload failure
v1.1.10
-------
### Bug
- **[COOK-3091](https://tickets.opscode.com/browse/COOK-3091)** - Fix checking `Chef::Config[:config_file]`
v1.1.8
------
- [COOK-1918] - Ohai cookbook to distribute plugins fails on windows
- [COOK-2096] - Ohai cookbook sets unix-only default path attribute
v1.1.6
------
- [COOK-2057] - distribution from another cookbok fails if ohai attributes are loaded after the other cookbook
v1.1.4
------
- [COOK-1128] - readme update, Replace reference to deprecated chef cookbook with one to chef-client
v1.1.2
------
- [COOK-1424] - prevent plugin_path growth to infinity
v1.1.0
------
- [COOK-1174] - custom_plugins is only conditionally available
- [COOK-1383] - allow plugins from other cookbooks
v1.0.2
------
- [COOK-463] ohai cookbook default recipe should only reload plugins if there were updates

68
cookbooks/ohai/README.md Normal file
View File

@@ -0,0 +1,68 @@
ohai Cookbook
=============
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.
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-client::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.
- `node['ohai']['plugins']` - sources of plugins, defaults to the `files/default/plugins` directory of this cookbook. You can add additional cookbooks by adding the name of the cookbook as a key and the path of the files directory as the value. You have to make sure that you don't have any file conflicts between multiple cookbooks. The last one to write wins.
- `node['ohai']['hints_path']` - location to drop off hints directory, default is `/etc/chef/ohai/hints`.
Usage
-----
Put the recipe `ohai` at the start of the node's run list to make sure that custom plugins are loaded early on in the Chef run and data is available for later recipes.
The execution of the custom plugins occurs within the recipe during the compile phase, so you can write new plugins and use the data they return in your Chef recipes.
For information on how to write custom plugins for Ohai, please see the Chef wiki pages.
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']`".
LWRP
----
### `ohai_hint`
Create hints file. You can find usage examples at `test/cookbooks/ohai_test/recipes/*.rb`.
#### Resource Attributes
- `hint_name` - The name of hints file and key. Should be string, default is name of resource.
- `content` - Values of hints. It will be used as automatic attributes. Should be Hash, default is empty Hash class.
Example
-------
For an example implementation, inspect the ohai_plugin.rb recipe in the nginx community cookbook.
License & Authors
-----------------
- Author:: Joshua Timberman (<joshua@opscode.com>)
- Author:: Seth Chisamore (<schisamo@opscode.com>)
```text
Copyright:: 2010-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.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
```

View File

@@ -0,0 +1,31 @@
#
# Cookbook Name:: ohai
# Attribute:: default
#
# Copyright 2010, Opscode, Inc
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# FHS location would be /var/lib/chef/ohai_plugins or similar.
case node["platform_family"]
when "windows"
default["ohai"]["plugin_path"] = "C:/chef/ohai_plugins"
default["ohai"]["hints_path"] = "C:/chef/ohai/hints"
else
default["ohai"]["plugin_path"] = "/etc/chef/ohai_plugins"
default["ohai"]["hints_path"] = "/etc/chef/ohai/hints"
end
# The list of plugins and their respective file locations
default["ohai"]["plugins"]["ohai"] = "plugins"

View File

@@ -0,0 +1 @@
This directory contains custom plugins for Ohai.

View File

@@ -0,0 +1,46 @@
{
"name": "ohai",
"version": "2.0.1",
"description": "Distributes a directory of custom ohai plugins",
"long_description": "ohai Cookbook\n=============\nCreates 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).\n\n\nAttributes\n----------\n- `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.\n\n 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-client::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.\n\n- `node['ohai']['plugins']` - sources of plugins, defaults to the `files/default/plugins` directory of this cookbook. You can add additional cookbooks by adding the name of the cookbook as a key and the path of the files directory as the value. You have to make sure that you don't have any file conflicts between multiple cookbooks. The last one to write wins.\n\n- `node['ohai']['hints_path']` - location to drop off hints directory, default is `/etc/chef/ohai/hints`.\n\nUsage\n-----\nPut the recipe `ohai` at the start of the node's run list to make sure that custom plugins are loaded early on in the Chef run and data is available for later recipes.\n\nThe execution of the custom plugins occurs within the recipe during the compile phase, so you can write new plugins and use the data they return in your Chef recipes.\n\nFor information on how to write custom plugins for Ohai, please see the Chef wiki pages.\n\nhttp://wiki.opscode.com/display/chef/Writing+Ohai+Plugins\n\n*PLEASE NOTE* - This recipe reloads the Ohai plugins a 2nd time during the Chef run if:\n\n* The \"`Ohai::Config[:plugin_path]`\" config setting has *NOT* been properly set in the Chef config file\n- 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']`\".\n\nLWRP\n----\n\n### `ohai_hint`\n\nCreate hints file. You can find usage examples at `test/cookbooks/ohai_test/recipes/*.rb`.\n\n#### Resource Attributes\n\n - `hint_name` - The name of hints file and key. Should be string, default is name of resource.\n - `content` - Values of hints. It will be used as automatic attributes. Should be Hash, default is empty Hash class.\n\n\nExample\n-------\nFor an example implementation, inspect the ohai_plugin.rb recipe in the nginx community cookbook.\n\n\nLicense & Authors\n-----------------\n- Author:: Joshua Timberman (<joshua@opscode.com>)\n- Author:: Seth Chisamore (<schisamo@opscode.com>)\n\n```text\nCopyright:: 2010-2011, Opscode, Inc\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n```\n",
"maintainer": "Opscode, Inc",
"maintainer_email": "cookbooks@opscode.com",
"license": "Apache 2.0",
"platforms": {
},
"dependencies": {
},
"recommendations": {
},
"suggestions": {
},
"conflicting": {
},
"providing": {
},
"replacing": {
},
"attributes": {
"ohai/plugin_path": {
"display_name": "Ohai Plugin Path",
"description": "Distribute plugins to this path.",
"type": "string",
"required": "optional",
"default": "/etc/chef/ohai_plugins"
},
"ohai/plugins": {
"display_name": "Ohai Plugin Sources",
"description": "Read plugins from these cookbooks and paths",
"type": "hash",
"required": "optional",
"default": {
"ohai": "plugins"
}
}
},
"groupings": {
},
"recipes": {
"ohai::default": "Distributes a directory of custom ohai plugins"
}
}

View File

@@ -0,0 +1,23 @@
name "ohai"
maintainer "Opscode, Inc"
maintainer_email "cookbooks@opscode.com"
license "Apache 2.0"
description "Distributes a directory of custom ohai plugins"
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
version "2.0.1"
recipe "ohai::default", "Distributes a directory of custom ohai plugins"
attribute "ohai/plugin_path",
:display_name => "Ohai Plugin Path",
:description => "Distribute plugins to this path.",
:type => "string",
:required => "optional",
:default => "/etc/chef/ohai_plugins"
attribute "ohai/plugins",
:display_name => "Ohai Plugin Sources",
:description => "Read plugins from these cookbooks and paths",
:type => "hash",
:required => "optional",
:default => {'ohai' => 'plugins'}

View File

@@ -0,0 +1,35 @@
def why_run_supported?
true
end
def build_ohai_hint_path
::File.join(node[:ohai][:hints_path], "#{new_resource.name}.json")
end
use_inline_resources
action :create do
if @current_resource.content != new_resource.content
directory node[:ohai][:hints_path] do
action :create
recursive true
end
file build_ohai_hint_path do
action :create
content JSON.pretty_generate(new_resource.content)
end
end
end
def load_current_resource
@current_resource = Chef::Resource::OhaiHint.new(new_resource.name)
if ::File.exist?(build_ohai_hint_path)
@current_resource.content(JSON.parse(::File.read(build_ohai_hint_path)))
else
@current_resource.content(nil)
end
@current_resource
end

View File

@@ -0,0 +1,55 @@
#
# Cookbook Name:: ohai
# Recipe:: default
#
# 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.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
reload_ohai = false
# Add plugin_path from node attributes if missing, and ensure a reload of
# ohai in that case
unless Ohai::Config[:plugin_path].include?(node['ohai']['plugin_path'])
Ohai::Config[:plugin_path] = [node['ohai']['plugin_path'], Ohai::Config[:plugin_path]].flatten.compact
reload_ohai ||= true
end
Chef::Log.info("ohai plugins will be at: #{node['ohai']['plugin_path']}")
# This is done during the compile phase so new plugins can be used in
# resources later in the run.
node['ohai']['plugins'].each_pair do |source_cookbook, path|
rd = remote_directory "#{node['ohai']['plugin_path']} for cookbook #{source_cookbook}" do
path node['ohai']['plugin_path']
cookbook source_cookbook
source path
mode '0755' unless platform_family?('windows')
recursive true
purge false
action :nothing
end
rd.run_action(:create)
reload_ohai ||= rd.updated?
end
resource = ohai 'custom_plugins' do
action :nothing
end
# Reload ohai if the client's plugin_path did not contain
# node['ohai']['plugin_path'], or new plugins were loaded
if reload_ohai
resource.run_action(:reload)
end

View File

@@ -0,0 +1,6 @@
actions :create, :delete
default_action :create
attribute :hint_name, :kind_of => String, :name_attribute => true
attribute :content, :kind_of => Hash, :default => {}