Update cookbooks

* Replace old nginx cookbook with new chef_nginx cookbooks
* Update application cookbook
This commit is contained in:
Greg Karékinian
2017-04-28 11:59:11 +02:00
parent 5d1d4832df
commit 4fb5390f9b
264 changed files with 3050 additions and 8605 deletions

View File

@@ -0,0 +1,2 @@
~FC016
~FC009

View File

@@ -1,7 +1,89 @@
# ohai Cookbook CHANGELOG
This file is used to list changes made in each version of the ohai cookbook.
## 5.0.4 (2017-04-25)
- Fix lack of .rb extension when deleting plugins.
## 5.0.3 (2017-04-06)
- Use class_eval again in the custom resource to provide Chef 12.5/12.6 compatibility
- Remove kind_of and use name_property not name_attribute
- Fix failures on Chef 13
## 5.0.2 (2017-03-24)
- Remove class_eval
## 5.0.1 (2017-03-14)
- Test with Delivery Local Mode
- Bump the dependency to 12.7+ due to failures on 12.5-12.6
## 5.0.0 (2017-02-23)
- Require Chef 12.5+ and remove compat_resource dependency
## 4.2.3 (2016-12-02)
- Prevent chef_version metadata from failing runs in Opsworks
- Better explain how to resolve the plugin_path issue
- Add suse as a supported platform
- Require at least compat_resource 12.14.7
## 4.2.2 (2016-09-19)
- Ignore case in plugin path check on Windows
## 4.2.1 (2016-09-08)
- Fix typo in compile warning text
- Depend on the latest compat_resource (12.14)
- Remove Chef 11 compat in the metadata
- Require Chef 12.1 not 12.0
- Define ohai_plugin matcher for Chefspec
## v4.2.0 (2016-07-19)
- Added the ability to specify the source cookbook for the cookbook_file or template used in the ohai_plugin resource.
- Added chef_version to the metadata
- Added testing on openSUSE and switched from Rubocop to Cookstyle
## v4.1.1 (2016-06-16)
- Fixed error in notifies reload for the delete action
- Bump the compat_resource requirement from 12.9+ to 12.10+ to prevent random failures
## v4.1.0 (2016-05-26)
- Added the ability to use templates and pass in variables with the plugin custom resource
## v4.0.2 (2016-05-23)
- Resolve failures on Windows nodes
## v4.0.1 (2016-05-19)
- Added .rb to the name of the plugins so they actually load
- Added testing to ensure the plugins are being loaded in the chef run
## v4.0.0 (2016-05-18)
### BREAKING CHANGE:
The 4.0 release of the Ohai cookbook removes the previous cookbook_file behavior that required forking the cookbook and adding your own plugins. Instead the cookbook ships with a new ohai_plugin custom resource for installing plugins. In addition to this new custom resource the cookbook now requires Chef 12+. See the readme and test recipe for examples. If you require Chef 11 support you'll need to pin to version 3.0 in your environment.
## v3.0.1 (2016-03-14)
- Fixed the Chefspec matchers
## v3.0.0 (2016-03-14)
- Change the default value for `node['ohai']['hints_path']` to use the Ohai config value. This should be the same value in most use cases, but if a custom path is specified in the chef client config this value will get used automatically by the cookbook.
- Removed backwards compatibility with Chefspec < 4.1 in the matchers library
- Fix bad link to the custom Ohai plugin documentation in the readme
- Improve documentation for `node['ohai']['plugin_path']`
## v2.1.0 (2016-01-26)
- Properly handle creating ohai hints without specifying the content. Previously if the content wasn't specified a deprecation notice would be thrown and the file would not be created
- Simplified the test suite and added inspec tests to ensure hints are created, especially if the content is not specified
- Added FreeBSD and Windows as supported platform in the metadata and add them to the Test Kitchen config
@@ -9,9 +91,11 @@ This file is used to list changes made in each version of the ohai cookbook.
- Updated testing Gems to the latest releases in the Gemfile
## v2.0.4 (2015-10-30)
- Resolved deprecation warnings with the Chefspec matchers
## v2.0.3 (2015-10-21)
- Validate the hints before loading them to avoid failures
- Added supported platforms to the metadata
- Updated .gitignore file
@@ -32,36 +116,47 @@ This file is used to list changes made in each version of the ohai cookbook.
- Added basic convergence Chefspec test
## 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/chef-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.chef.io/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

View File

@@ -1,19 +1,15 @@
<!-- This is a generated file. Please do not edit directly -->
# Maintainers
This file lists how this cookbook project is maintained. When making changes to the system, this
file tells you who needs to review your patch - you need a simple majority of maintainers
for the relevant subsystems to provide a :+1: on your pull request. Additionally, you need
to not receive a veto from a Lieutenant or the Project Lead.
Check out [How Cookbooks are Maintained](https://github.com/chef-cookbooks/community_cookbook_documentation/blob/master/CONTRIBUTING.MD)
for details on the process and how to become a maintainer or the project lead.
This file lists how this cookbook project is maintained. When making changes to the system, this file tells you who needs to review your patch - you need a review from an existing maintainer for the cookbook to provide a :+1: on your pull request. Additionally, you need to not receive a veto from a Lieutenant or the Project Lead.
Check out [How Cookbooks are Maintained](https://github.com/chef-cookbooks/community_cookbook_documentation/blob/master/CONTRIBUTING.MD) for details on the process and how to become a maintainer or the project lead.
# Project Maintainer
* [Tim Smith](https://github.com/tas50)
# Maintainers
* [Jennifer Davis](https://github.com/sigje)
* [Sean OMeara](https://github.com/someara)
* [Tim Smith](https://github.com/tas50)
* [Thom May](https://github.com/thommay)

View File

@@ -1,59 +1,120 @@
# ohai Cookbook
[![Build Status](https://travis-ci.org/chef-cookbooks/ohai.svg?branch=master)](https://travis-ci.org/chef-cookbooks/ohai) [![Cookbook Version](https://img.shields.io/cookbook/v/ohai.svg)](https://supermarket.chef.io/cookbooks/ohai)
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).
[![Build Status](https://travis-ci.org/chef-cookbooks/ohai.svg?branch=master)](https://travis-ci.org/chef-cookbooks/ohai) [![Build status](https://ci.appveyor.com/api/projects/status/lgok2kr6l007s8hf/branch/master?svg=true)](https://ci.appveyor.com/project/ChefWindowsCookbooks/ohai/branch/master) [![Cookbook Version](https://img.shields.io/cookbook/v/ohai.svg)](https://supermarket.chef.io/cookbooks/ohai)
Contains custom resources for adding Ohai hints and installing custom Ohai plugins. Handles path creation as well as the reloading of Ohai so that new data will be available during the same run.
## Requirements
### Platforms
- Debian/Ubuntu
- RHEL/CentOS/Scientific/Amazon/Oracle
- openSUSE / SUSE Enterprise Linux
- FreeBSD
- Windows
### Chef
- Chef 11+
- Chef 12.5+
### Cookbooks
- none
## 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.
## Custom Resources
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.chef.io/display/chef/Writing+Ohai+Plugins](http://wiki.chef.io/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`.
Creates Ohai hint files, which are consumed by Ohai plugins in order to determine if they should run or not.
#### 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.
- `content` - Values of hints. It will be used as automatic attributes. Should be Hash, default is empty Hash
- `compile_time` - Should the resource run at compile time. This defaults to true
#### Examples
Hint file installed to the default directory:
```ruby
ohai_hint 'ec2'
```
Hint file not installed at compile time:
```ruby
ohai_hint 'ec2' do
compile_time false
end
```
Hint file installed with content:
```ruby
ohai_hint 'raid_present' do
content Hash[:a, 'test_content']
end
```
#### ChefSpec Matchers
You can check for the creation or deletion of ohai hints with chefspec using these custom matches:
- create_ohai_hint
- delete_ohai_hint
## Example
For an example implementation, inspect the ohai_plugin.rb recipe in the nginx community cookbook.
### `ohai_plugin`
Installs custom Ohai plugins.
#### Resource Attributes
- `plugin_name` - The name to give the plugin on the filesystem. Should be string, default is name of resource.
- `path` - The path to your custom plugin directory. Defaults to a directory named 'plugins' under the directory 'ohai' in the Chef config dir.
- `source_file` - The source file for the plugin in your cookbook if not NAME.rb.
- `cookbook` - The cookbook where the source file exists if not the cookbook where the ohai_plugin resource is running from.
- `resource` - The resource type for the plugin file. Either `:cookbook_file` or `:template`. Defaults to `:cookbook_file`.
- `variables` - Usable only if `resource` is `:template`. Defines the template's variables.
- `compile_time` - Should the resource run at compile time. This defaults to `true`.
#### examples
Simple Ohai plugin installation:
```ruby
ohai_plugin 'my_custom_plugin'
```
Installation where the resource doesn't match the filename and you install to a custom plugins dir:
```ruby
ohai_plugin 'My Ohai Plugin' do
name 'my_custom_plugin'
path '/my/custom/path/'
end
```
Installation using a template:
```ruby
ohai_plugin 'My Templated Plugin' do
name 'templated_plugin'
resource :template
variables node_type: :web_server
end
```
#### ChefSpec Matchers
You can check for the creation or deletion of ohai plugins with chefspec using these custom matches:
- create_ohai_plugin
- delete_ohai_plugin
## License & Authors
**Author:** Cookbook Engineering Team ([cookbooks@chef.io](mailto:cookbooks@chef.io))
**Copyright:** 2011-2016, Chef Software, Inc.

View File

@@ -1,31 +0,0 @@
#
# Cookbook Name:: ohai
# Attribute:: default
#
# Copyright 2010-2016, Chef Software, 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'] = "#{ENV['systemdrive']}/chef/ohai_plugins"
default['ohai']['hints_path'] = "#{ENV['systemdrive']}/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

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

View File

@@ -1,14 +1,27 @@
# encoding: utf-8
#
# Cookbook:: ohai
# Library:: matchers
#
# Author:: Tim Smith (<tsmith@chef.io>)
#
# Copyright:: 2016-2017, Chef Software, 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.
#
if defined?(ChefSpec)
if ChefSpec.respond_to?(:define_matcher)
# ChefSpec >= 4.1
ChefSpec.define_matcher(:ohai_hint)
elsif defined?(ChefSpec::Runner) &&
ChefSpec::Runner.respond_to?(:define_runner_method)
# ChefSpec < 4.1
ChefSpec::Runner.define_runner_method(:ohai_hint)
end
ChefSpec.define_matcher :ohai_hint
ChefSpec.define_matcher :ohai_plugin
def create_ohai_hint(resource)
ChefSpec::Matchers::ResourceMatcher.new(:ohai_hint, :create, resource)
@@ -18,4 +31,11 @@ if defined?(ChefSpec)
ChefSpec::Matchers::ResourceMatcher.new(:ohai_hint, :delete, resource)
end
def create_ohai_plugin(resource)
ChefSpec::Matchers::ResourceMatcher.new(:ohai_plugin, :create, resource)
end
def delete_ohai_plugin(resource)
ChefSpec::Matchers::ResourceMatcher.new(:ohai_plugin, :delete, resource)
end
end

View File

@@ -1 +1 @@
{"name":"ohai","version":"2.1.0","description":"Distributes a directory of custom ohai plugins","long_description":"# ohai Cookbook\n[![Build Status](https://travis-ci.org/chef-cookbooks/ohai.svg?branch=master)](https://travis-ci.org/chef-cookbooks/ohai) [![Cookbook Version](https://img.shields.io/cookbook/v/ohai.svg)](https://supermarket.chef.io/cookbooks/ohai)\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## Requirements\n### Platforms\n- Debian/Ubuntu\n- RHEL/CentOS/Scientific/Amazon/Oracle\n- FreeBSD\n- Windows\n\n### Chef\n- Chef 11+\n\n### Cookbooks\n- none\n\n## Attributes\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- `node['ohai']['hints_path']` - location to drop off hints directory, default is `/etc/chef/ohai/hints`.\n\n## Usage\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\n[http://wiki.chef.io/display/chef/Writing+Ohai+Plugins](http://wiki.chef.io/display/chef/Writing+Ohai+Plugins)\n\n_PLEASE NOTE_ - This recipe reloads the Ohai plugins a 2nd time during the Chef run if:\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\n## LWRP\n### `ohai_hint`\nCreate hints file. You can find usage examples at `test/cookbooks/ohai_test/recipes/*.rb`.\n\n#### Resource Attributes\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#### ChefSpec Matchers\nYou can check for the creation or deletion of ohai hints with chefspec using these custom matches:\n- create_ohai_hint\n- delete_ohai_hint\n\n## Example\nFor an example implementation, inspect the ohai_plugin.rb recipe in the nginx community cookbook.\n\n## License & Authors\n**Author:** Cookbook Engineering Team ([cookbooks@chef.io](mailto:cookbooks@chef.io))\n\n**Copyright:** 2011-2016, Chef Software, Inc.\n\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":"Chef Software, Inc.","maintainer_email":"cookbooks@chef.io","license":"Apache 2.0","platforms":{"ubuntu":">= 0.0.0","debian":">= 0.0.0","centos":">= 0.0.0","redhat":">= 0.0.0","amazon":">= 0.0.0","scientific":">= 0.0.0","fedora":">= 0.0.0","oracle":">= 0.0.0","freebsd":">= 0.0.0","windows":">= 0.0.0"},"dependencies":{},"recommendations":{},"suggestions":{},"conflicting":{},"providing":{},"replacing":{},"attributes":{},"groupings":{},"recipes":{"ohai::default":"Distributes a directory of custom ohai plugins"}}
{"name":"ohai","version":"5.0.4","description":"Provides custom resources for installing Ohai hints and plugins","long_description":"# ohai Cookbook\n\n[![Build Status](https://travis-ci.org/chef-cookbooks/ohai.svg?branch=master)](https://travis-ci.org/chef-cookbooks/ohai) [![Build status](https://ci.appveyor.com/api/projects/status/lgok2kr6l007s8hf/branch/master?svg=true)](https://ci.appveyor.com/project/ChefWindowsCookbooks/ohai/branch/master) [![Cookbook Version](https://img.shields.io/cookbook/v/ohai.svg)](https://supermarket.chef.io/cookbooks/ohai)\n\nContains custom resources for adding Ohai hints and installing custom Ohai plugins. Handles path creation as well as the reloading of Ohai so that new data will be available during the same run.\n\n## Requirements\n\n### Platforms\n\n- Debian/Ubuntu\n- RHEL/CentOS/Scientific/Amazon/Oracle\n- openSUSE / SUSE Enterprise Linux\n- FreeBSD\n- Windows\n\n### Chef\n\n- Chef 12.5+\n\n### Cookbooks\n\n- none\n\n## Custom Resources\n\n### `ohai_hint`\n\nCreates Ohai hint files, which are consumed by Ohai plugins in order to determine if they should run or not.\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\n- `compile_time` - Should the resource run at compile time. This defaults to true\n\n#### Examples\n\nHint file installed to the default directory:\n\n```ruby\nohai_hint 'ec2'\n```\n\nHint file not installed at compile time:\n\n```ruby\nohai_hint 'ec2' do\n compile_time false\nend\n```\n\nHint file installed with content:\n\n```ruby\nohai_hint 'raid_present' do\n content Hash[:a, 'test_content']\nend\n```\n\n#### ChefSpec Matchers\n\nYou can check for the creation or deletion of ohai hints with chefspec using these custom matches:\n\n- create_ohai_hint\n- delete_ohai_hint\n\n### `ohai_plugin`\n\nInstalls custom Ohai plugins.\n\n#### Resource Attributes\n\n- `plugin_name` - The name to give the plugin on the filesystem. Should be string, default is name of resource.\n- `path` - The path to your custom plugin directory. Defaults to a directory named 'plugins' under the directory 'ohai' in the Chef config dir.\n- `source_file` - The source file for the plugin in your cookbook if not NAME.rb.\n- `cookbook` - The cookbook where the source file exists if not the cookbook where the ohai_plugin resource is running from.\n- `resource` - The resource type for the plugin file. Either `:cookbook_file` or `:template`. Defaults to `:cookbook_file`.\n- `variables` - Usable only if `resource` is `:template`. Defines the template's variables.\n- `compile_time` - Should the resource run at compile time. This defaults to `true`.\n\n#### examples\n\nSimple Ohai plugin installation:\n\n```ruby\nohai_plugin 'my_custom_plugin'\n```\n\nInstallation where the resource doesn't match the filename and you install to a custom plugins dir:\n\n```ruby\nohai_plugin 'My Ohai Plugin' do\n name 'my_custom_plugin'\n path '/my/custom/path/'\nend\n```\n\nInstallation using a template:\n\n```ruby\nohai_plugin 'My Templated Plugin' do\n name 'templated_plugin'\n resource :template\n variables node_type: :web_server\nend\n```\n\n#### ChefSpec Matchers\n\nYou can check for the creation or deletion of ohai plugins with chefspec using these custom matches:\n\n- create_ohai_plugin\n- delete_ohai_plugin\n\n## License & Authors\n\n**Author:** Cookbook Engineering Team ([cookbooks@chef.io](mailto:cookbooks@chef.io))\n\n**Copyright:** 2011-2016, Chef Software, Inc.\n\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":"Chef Software, Inc.","maintainer_email":"cookbooks@chef.io","license":"Apache-2.0","platforms":{"ubuntu":">= 0.0.0","debian":">= 0.0.0","centos":">= 0.0.0","redhat":">= 0.0.0","amazon":">= 0.0.0","scientific":">= 0.0.0","fedora":">= 0.0.0","oracle":">= 0.0.0","suse":">= 0.0.0","opensuse":">= 0.0.0","opensuseleap":">= 0.0.0","freebsd":">= 0.0.0","windows":">= 0.0.0","zlinux":">= 0.0.0"},"dependencies":{},"recommendations":{},"suggestions":{},"conflicting":{},"providing":{},"replacing":{},"attributes":{},"groupings":{},"recipes":{},"source_url":"https://github.com/chef-cookbooks/ohai","issues_url":"https://github.com/chef-cookbooks/ohai/issues","chef_version":[[">= 12.5"]],"ohai_version":[]}

View File

@@ -1,46 +0,0 @@
def why_run_supported?
true
end
def ohai_hint_path
::File.join(node['ohai']['hints_path'], "#{new_resource.name}.json")
end
def build_content
# passing nil to file produces deprecation warnings so pass an empty string
return '' if new_resource.content.nil? || new_resource.content.empty?
JSON.pretty_generate(new_resource.content)
end
use_inline_resources
action :create do
# don't create the file if the existing file was empty and so is the new one
# this avoids bogus content updates on every chef run
unless (@current_resource.content && @current_resource.content.empty?) && new_resource.content.nil?
directory node['ohai']['hints_path'] do
action :create
recursive true
end
file ohai_hint_path do
action :create
content build_content
end
end
end
def load_current_resource
@current_resource = Chef::Resource::OhaiHint.new(new_resource.name)
if ::File.exist?(ohai_hint_path)
Chef::Log.debug("Existing ohai hint at #{ohai_hint_path} found. Attempting to parse JSON")
begin
@current_resource.content(JSON.parse(::File.read(ohai_hint_path)))
rescue JSON::ParserError
@current_resource.content({})
Chef::Log.debug("Could not parse JSON in ohai hint at #{ohai_hint_path}. It's probably an empty hint file")
end
end
@current_resource
end

View File

@@ -1,8 +1,8 @@
#
# Cookbook Name:: ohai
# Cookbook:: ohai
# Recipe:: default
#
# Copyright 2011-2016, Chef Software, Inc
# Copyright:: 2011-2017, Chef Software, Inc
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -17,36 +17,4 @@
# 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
resource.run_action(:reload) if reload_ohai
Chef::Log.warn('The Ohai cookbook default recipe has no content as of the 4.0 release. See the readme for instructions on using the custom resources.')

View File

@@ -1,5 +1,55 @@
actions :create, :delete
default_action :create
property :hint_name, String, name_property: true
property :content, Hash
property :compile_time, [true, false], default: true
attribute :hint_name, kind_of: String, name_attribute: true
attribute :content, kind_of: Hash
action :create do
directory ::Ohai::Config.ohai.hints_path.first do
action :create
recursive true
end
file ohai_hint_path do
action :create
content build_content
end
end
action :delete do
file ohai_hint_path do
action :delete
notifies :reload, ohai[reload ohai post hint removal]
end
ohai 'reload ohai post hint removal' do
action :nothing
end
end
action_class.class_eval do
def ohai_hint_path
path = ::File.join(::Ohai::Config.ohai.hints_path.first, new_resource.hint_name)
path << '.json' unless path.end_with?('.json')
path
end
def build_content
# passing nil to file produces deprecation warnings so pass an empty string
return nil if new_resource.content.nil? || new_resource.content.empty?
JSON.pretty_generate(new_resource.content)
end
def file_content(path)
return JSON.parse(::File.read(path))
rescue JSON::ParserError
Chef::Log.debug("Could not parse JSON in ohai hint at #{ohai_hint_path}. It's probably an empty hint file")
return nil
end
end
# this resource forces itself to run at compile_time
def after_created
return unless compile_time
Array(action).each do |action|
run_action(action)
end
end

View File

@@ -0,0 +1,117 @@
property :plugin_name, String, name_property: true
property :path, String
property :source_file, String
property :cookbook, String
property :resource, [:cookbook_file, :template], default: :cookbook_file
property :variables, Hash
property :compile_time, [true, false], default: true
action :create do
# why create_if_missing you ask?
# no one can agree on perms and this allows them to manage the perms elsewhere
directory desired_plugin_path do
action :create
recursive true
not_if { ::File.exist?(desired_plugin_path) }
end
if new_resource.resource.eql?(:cookbook_file)
cookbook_file ::File.join(desired_plugin_path, new_resource.plugin_name + '.rb') do
cookbook new_resource.cookbook
source new_resource.source_file || "#{new_resource.plugin_name}.rb"
notifies :reload, "ohai[#{new_resource.plugin_name}]", :immediately
end
elsif new_resource.resource.eql?(:template)
template ::File.join(desired_plugin_path, new_resource.plugin_name + '.rb') do
cookbook new_resource.cookbook
source new_resource.source_file || "#{new_resource.plugin_name}.rb"
variables new_resource.variables
notifies :reload, "ohai[#{new_resource.plugin_name}]", :immediately
end
end
# Add the plugin path to the ohai plugin path if need be and warn
# the user that this is going to result in a reload every run
unless in_plugin_path?(desired_plugin_path)
plugin_path_warning
Chef::Log.warn("Adding #{desired_plugin_path} to the Ohai plugin path for this chef-client run only")
add_to_plugin_path(desired_plugin_path)
reload_required = true
end
ohai new_resource.plugin_name do
action :nothing
action :reload if reload_required
end
end
action :delete do
file ::File.join(desired_plugin_path, new_resource.plugin_name + '.rb') do
action :delete
notifies :reload, 'ohai[reload ohai post plugin removal]'
end
ohai 'reload ohai post plugin removal' do
action :nothing
end
end
action_class.class_eval do
# return the path property if specified or
# CHEF_CONFIG_PATH/ohai/plugins if a path isn't specified
def desired_plugin_path
if new_resource.path
new_resource.path
else
::File.join(chef_config_path, 'ohai', 'plugins')
end
end
# return the chef config files dir or fail hard
def chef_config_path
if Chef::Config['config_file']
::File.dirname(Chef::Config['config_file'])
else
Chef::Application.fatal!("No chef config file defined. Are you running \
chef-solo? If so you will need to define a path for the ohai_plugin as the \
path cannot be determined")
end
end
# is the desired plugin dir in the ohai config plugin dir array?
def in_plugin_path?(path)
# get the directory where we plan to stick the plugin (not the actual file path)
desired_dir = ::File.directory?(path) ? path : ::File.dirname(path)
case node['platform']
when 'windows'
::Ohai::Config.ohai['plugin_path'].map(&:downcase).include?(desired_dir.downcase)
else
::Ohai::Config.ohai['plugin_path'].include?(desired_dir)
end
end
def add_to_plugin_path(path)
::Ohai::Config.ohai['plugin_path'] << path # new format
end
# we need to warn the user that unless the path for this plugin is in Ohai's
# plugin path already we're going to have to reload Ohai on every Chef run.
# Ideally in future versions of Ohai /etc/chef/ohai/plugins is in the path.
def plugin_path_warning
Chef::Log.warn("The Ohai plugin_path does not include #{desired_plugin_path}. \
Ohai will reload on each chef-client run in order to add this directory to the \
path unless you modify your client.rb configuration to add this directory to \
plugin_path. The plugin_path can be set via the chef-client::config recipe. \
See 'Ohai Settings' at https://docs.chef.io/config_rb_client.html#ohai-settings \
for more details.")
end
end
# this resource forces itself to run at compile_time
def after_created
return unless compile_time
Array(action).each do |action|
run_action(action)
end
end