Coder Social home page Coder Social logo

ohai's Introduction

ohai Cookbook

Build Status Build status Cookbook Version

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.

Deprecation

This cookbook has been deprecated as all functionality here is now built into the Chef Infra Client itself. The ohai_hint resource now ships in Chef Infra Client and any plugins can be installed by placing them in an ohai directory within a cookbook in your runlist.

Requirements

Platforms

  • Debian/Ubuntu
  • RHEL/CentOS/Scientific/Amazon/Oracle
  • openSUSE / SUSE Enterprise Linux
  • FreeBSD
  • Windows

Chef

  • Chef 13+

Cookbooks

  • none

Custom Resources

ohai_hint

Creates Ohai hint files, which are consumed by Ohai plugins in order to determine if they should run or not.

Resource Properties

  • 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
  • compile_time - Should the resource run at compile time. This defaults to true

Examples

Hint file installed to the default directory:

ohai_hint 'ec2'

Hint file not installed at compile time:

ohai_hint 'ec2' do
  compile_time false
end

Hint file installed with content:

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

ohai_plugin

Installs custom Ohai plugins.

Resource Properties

  • 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.
  • load_single_plugin - Reload all plugins unless this value is set to true. Load only the named plugin.

examples

Simple Ohai plugin installation:

ohai_plugin 'my_custom_plugin'

Installation where the resource doesn't match the filename and you install to a custom plugins dir:

ohai_plugin 'My Ohai Plugin' do
  name 'my_custom_plugin'
  path '/my/custom/path/'
end

Installation using a template:

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

Maintainers

This cookbook is maintained by Chef's Community Cookbook Engineering team. Our goal is to improve cookbook quality and to aid the community in contributing to cookbooks. To learn more about our team, process, and design goals see our team documentation. To learn more about contributing to cookbooks like this see our contributing documentation, or if you have general questions about this cookbook come chat with us in #cookbok-engineering on the Chef Community Slack

License

Copyright: 2011-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.

ohai's People

Contributors

bkw avatar chrisroberts avatar cwebberops avatar dwmarshall avatar josephholsten avatar kamaradclimber avatar ketank-new avatar lamont-granquist avatar markgibbons avatar meineerde avatar mhudson avatar mitch-roblox avatar modille avatar nathenharvey avatar nukemberg avatar patcox avatar pdf avatar priestjim avatar sawanoboly avatar schisamo avatar sethvargo avatar stromweld avatar tas50 avatar trevorlauder avatar unixorn avatar xorimabot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ohai's Issues

Error on Ohai 5.2.3 - ohai/plugin_helpers.rb is a version 6 plugin. Version 6 plugins are no longer supported by Ohai.

Cookbook version

ohai (5.2.3)

Chef-client version

chef-client -v
Chef: 14.2.0

Platform Details

cat /etc/os-release
NAME="Amazon Linux AMI"
VERSION="2017.09"
ID="amzn"
ID_LIKE="rhel fedora"
VERSION_ID="2017.09"
PRETTY_NAME="Amazon Linux AMI 2017.09"
ANSI_COLOR="0;33"
CPE_NAME="cpe:/o:amazon:linux:2017.09:ga"
HOME_URL="http://aws.amazon.com/amazon-linux-ami/"

cloud provider EC2

Error:

1530265806,,ui,message,    amazon-ebs: Synchronizing Cookbooks:
1530265806,,ui,message,    amazon-ebs:   - cfncluster (1.5.1)
1530265807,,ui,message,    amazon-ebs:   - build-essential (8.1.1)
1530265807,,ui,message,    amazon-ebs:   - poise-python (1.7.0)
1530265807,,ui,message,    amazon-ebs:   - tar (2.1.1)
1530265807,,ui,message,    amazon-ebs:   - selinux (2.1.1)
1530265807,,ui,message,    amazon-ebs:   - nfs (2.5.1)
1530265807,,ui,message,    amazon-ebs:   - sysctl (1.0.5)
1530265807,,ui,message,    amazon-ebs:   - yum (5.1.0)
1530265807,,ui,message,    amazon-ebs:   - yum-epel (3.1.0)
1530265807,,ui,message,    amazon-ebs:   - openssh (2.6.3)
1530265807,,ui,message,    amazon-ebs:   - apt (7.0.0)
1530265807,,ui,message,    amazon-ebs:   - hostname (0.4.2)
1530265807,,ui,message,    amazon-ebs:   - line (1.0.6)
1530265807,,ui,message,    amazon-ebs:   - seven_zip (3.0.0)
1530265807,,ui,message,    amazon-ebs:   - mingw (2.0.2)
1530265807,,ui,message,    amazon-ebs:   - poise (2.8.1)
1530265807,,ui,message,    amazon-ebs:   - poise-languages (2.1.2)
1530265807,,ui,message,    amazon-ebs:   - ohai (5.2.3)
1530265808,,ui,message,    amazon-ebs:   - iptables (4.3.4)
1530265808,,ui,message,    amazon-ebs:   - hostsfile (3.0.1)
1530265808,,ui,message,    amazon-ebs:   - windows (4.3.2)
1530265808,,ui,message,    amazon-ebs:   - poise-archive (1.5.0)
1530265808,,ui,message,    amazon-ebs: Installing Cookbook Gems:
1530265808,,ui,message,    amazon-ebs: Compiling Cookbooks...
1530265808,,ui,message,    amazon-ebs:
1530265808,,ui,message,    amazon-ebs: Running handlers:
1530265808,,ui,message,    amazon-ebs: [2018-06-29T09:50:08+00:00] ERROR: Running exception handlers
1530265808,,ui,message,    amazon-ebs: Running handlers complete
1530265808,,ui,message,    amazon-ebs: [2018-06-29T09:50:08+00:00] ERROR: Exception handlers complete
1530265808,,ui,message,    amazon-ebs: Chef Client failed. 0 resources updated in 04 seconds
1530265808,,ui,message,    amazon-ebs: [2018-06-29T09:50:08+00:00] FATAL: Stacktrace dumped to /tmp/packer-chef-solo/local-mode-cache/cache/chef-stacktrace.out
1530265808,,ui,message,    amazon-ebs: [2018-06-29T09:50:08+00:00] FATAL: Please provide the contents of the stacktrace.out file if you file a bug report
1530265808,,ui,message,    amazon-ebs: [2018-06-29T09:50:08+00:00] FATAL: Ohai::Exceptions::IllegalPluginDefinition: [DEPRECATION] Plugin at /tmp/packer-chef-solo/ohai/cookbook_plugins/ohai/plugin_helpers.rb is a version 6 plugin. Version 6 plugins are no longer supported by Ohai. This plugin will need to be updated to the v7 Ohai plugin format. See https://docs.chef.io/ohai_custom.html for v7 syntax.
1530265808,,ui,error,==> amazon-ebs: Error executing Chef: Non-zero exit status: 1

Stacktrace:

cat /tmp/packer-chef-solo/local-mode-cache/cache/chef-stacktrace.out
Generated at 2018-06-29 09:50:08 +0000
Ohai::Exceptions::IllegalPluginDefinition: [DEPRECATION] Plugin at /tmp/packer-chef-solo/ohai/cookbook_plugins/ohai/plugin_helpers.rb is a version 6 plugin. Version 6 plugins are no longer supported by Ohai. This plugin will need to be updated to the v7 Ohai plugin format. See https://docs.chef.io/ohai_custom.html for v7 syntax.
/opt/chef/embedded/lib/ruby/gems/2.5.0/gems/ohai-14.2.0/lib/ohai/loader.rb:122:in `load_plugin_class'
/opt/chef/embedded/lib/ruby/gems/2.5.0/gems/ohai-14.2.0/lib/ohai/loader.rb:83:in `block in load_additional'
/opt/chef/embedded/lib/ruby/gems/2.5.0/gems/ohai-14.2.0/lib/ohai/loader.rb:81:in `collect'
/opt/chef/embedded/lib/ruby/gems/2.5.0/gems/ohai-14.2.0/lib/ohai/loader.rb:81:in `load_additional'
/opt/chef/embedded/lib/ruby/gems/2.5.0/gems/ohai-14.2.0/lib/ohai/system.rb:115:in `run_additional_plugins'
/opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.2.0/lib/chef/run_context/cookbook_compiler.rb:122:in `compile_ohai_plugins'
/opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.2.0/lib/chef/run_context/cookbook_compiler.rb:75:in `compile'
/opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.2.0/lib/chef/run_context.rb:199:in `load'
/opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.2.0/lib/chef/policy_builder/expand_node_object.rb:97:in `setup_run_context'
/opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.2.0/lib/chef/client.rb:512:in `setup_run_context'
/opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.2.0/lib/chef/client.rb:278:in `run'
/opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.2.0/lib/chef/application.rb:303:in `run_with_graceful_exit_option'
/opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.2.0/lib/chef/application.rb:279:in `block in run_chef_client'
/opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.2.0/lib/chef/local_mode.rb:44:in `with_server_connectivity'
/opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.2.0/lib/chef/application.rb:261:in `run_chef_client'
/opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.2.0/lib/chef/application/client.rb:441:in `run_application'
/opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.2.0/lib/chef/application.rb:66:in `run'
/opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.2.0/bin/chef-client:26:in `<top (required)>'
/usr/bin/chef-client:75:in `load'
/usr/bin/chef-client:75:in `<main>'

/tmp/packer-chef-solo/ohai/cookbook_plugins/ohai/plugin_helpers.rb is

cat /tmp/packer-chef-solo/ohai/cookbook_plugins/ohai/plugin_helpers.rb
#
# Cookbook:: ohai
# Library:: plugin_helpers
#
# Author:: Tim Smith (<[email protected]>)
#
# Copyright:: 2017-2018, 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.
#

module OhaiCookbook
  module PluginHelpers
    # 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.chomp('/') # if the user gave us /foo/bar/ we need /foo/bar for later comparison
      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)
      normalized_path = normalize_path(path)
      # get the directory where we plan to stick the plugin (not the actual file path)
      desired_dir = ::File.directory?(normalized_path) ? normalized_path : ::File.dirname(normalized_path)
      ::Ohai::Config.ohai['plugin_path'].map { |x| normalize_path(x) }.any? do |d|
        desired_dir.start_with?(d)
      end
    end

    # return path to lower and with forward slashes so we can compare it
    # this works around the 3 different way we can represent windows paths
    def normalize_path(path)
      path.downcase.gsub(/\\+/, '/')
    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
end

which is latest version (5.2.3)

undefined method `config' for Ohai:Module

Cookbook version

3.0.1

Chef-client version

11.10.4

Platform Details

AWS - Ubuntu 14.04 Trusty

Scenario:

I am trying to deploy one of my apps which uses this cookbook as a dependency

Steps to Reproduce:

This is happening during the cookbook compile time.

Expected Result:

Execution of the cookbook build process to continue

Actual Result:

Recipe Compile Error in /var/lib/aws/opsworks/cache.stage2/cookbooks/ohai/attributes/default.rb

NoMethodError

undefined method `config' for Ohai:Module

Cookbook Trace:

/var/lib/aws/opsworks/cache.stage2/cookbooks/ohai/attributes/default.rb:30:in `from_file'

Relevant File Content:

/var/lib/aws/opsworks/cache.stage2/cookbooks/ohai/attributes/default.rb:

23: "#{ENV['systemdrive']}/chef/ohai_plugins"
24: else
25: '/etc/chef/ohai_plugins'
26: end
27:
28: # The list of plugins and their respective file locations
29: default['ohai']['plugins']['ohai'] = 'plugins'
30>> default['ohai']['hints_path'] = Ohai.config[:hints_path].first
31:

Interesting Plugin Error with Chef 13

Cookbook version

5.0.3

Chef-client version

13.0.118 (also 13.1.5)

Platform Details

Ubuntu 16.04

Scenario:

Use Packer to make an AMI with a Chef-Solo provisioner.

Steps to Reproduce:

We can only produce the error on our Jenkins server.
Running the same Packer job locally (OSX) does not produce the issue.

Expected Result:

Ohai cookbook to load

Actual Result:

�[0;32m    amazon-ebs: [2017-04-25T18:26:02+00:00] WARN: [DEPRECATION] Plugin at /tmp/packer-chef-solo/ohai/cookbook_plugins/ohai/matchers.rb is a version 6 plugin. Version 6 plugins will not be supported in future releases of Ohai. Please upgrade your plugin to version 7 plugin syntax. For more information visit here: docs.chef.io/ohai_custom.html�[0m
�[0;32m    amazon-ebs:�[0m
�[0;32m    amazon-ebs: Running handlers:�[0m
�[0;32m    amazon-ebs: [2017-04-25T18:26:02+00:00] ERROR: Running exception handlers�[0m
�[0;32m    amazon-ebs: Running handlers complete�[0m
�[0;32m    amazon-ebs: [2017-04-25T18:26:02+00:00] ERROR: Exception handlers complete�[0m
�[0;32m    amazon-ebs: Chef Client failed. 0 resources updated in 03 seconds�[0m
�[0;32m    amazon-ebs: [2017-04-25T18:26:02+00:00] FATAL: Stacktrace dumped to /tmp/packer-chef-solo/local-mode-cache/cache/chef-stacktrace.out�[0m
�[0;32m    amazon-ebs: [2017-04-25T18:26:02+00:00] FATAL: Please provide the contents of the stacktrace.out file if you file a bug report�[0m
�[0;32m    amazon-ebs: [2017-04-25T18:26:02+00:00] ERROR: wrong number of arguments (given 1, expected 3)�[0m
�[0;32m    amazon-ebs: [2017-04-25T18:26:02+00:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)�[0m

So we use Packer to build amis. We switched to Chef 13 and tested locally (Macbook), and were able to build an ami in AWS with out issue. So we tried to run the same Packer command on our Jenkins server and get the output above.

Note though, that output is being reported by the AWS instance that Packer is provisioning, not Jenkins itself.

We can work around this issue by using Chef 12.19.x. We only get this error on Chef 13 and only when our Jenkins runs Packer.

Both locally and Jenkins run Chef-DK 1.3.43 and Packer 1.0.0. They also use the same Berksfile as well.

So far the only error we have to go on is the above Ohai cookbook error.

v5.0.1 not on Supermarket

Cookbook version

v5.0.1

Chef-client version

12.10.24

Platform Details

Ubuntu 14.04

Not super important since the change from 5.0.0 to 5.0.1 is not that big, but 5.0.1 does not seem to have made it to Supermarket (no v5.0.1 tag either).

Plugin path check is always case-sensitive

Cookbook version

4.2.0

Chef-client version

12.13.37

Platform Details

Windows Server 2012r2

Scenario:

On a case-insensitive filesystem, add the ohai plugin path with a lowercase drive letter and then use the ohai_plugin resource with the default value for the path attribute.

Steps to Reproduce:

In your client.rb, add:

# Lowercase drive letter
ohai.plugin_path << 'c:/chef/ohai/plugins'

And in your recipe, add:

ohai_plugin 'My Templated Plugin' do
  name 'templated_plugin'
  resource :template
  variables node_type: :web_server
end

Expected Result:

From a clean slate, the ohai_plugin resource should execute once, and then not execute/update on the next chef-client run if no changes were made.

Actual Result:

It executes/updates on each chef-client run.

This is because ::File.dirname(Chef::Config['config_file']) returns uppercase "C:/chef/ohai/plugins" whereas ::Ohai::Config.ohai['plugin_path'] includes lowercase "c:/chef/ohai/plugins" which causes #include? to return false.

https://github.com/chef-cookbooks/ohai/blob/master/resources/plugin.rb#L48

disabled_plugins causes WARN messages.

Setting:

default_attributes(
  ohai: {
    disabled_plugins: %w(
      :Cloud
      :Azure
      :Cloudstack
      :CloudV2
      :EC2
      :Eucalyptus
      :GCE
      :Joyent
      :Linode
      :Rackspace
    )
  }
)

Causes Chef to spew this WARNing:

[2016-03-02T15:48:59-05:00] WARN: Ohai::Config[:disabled_plugins] is set. Ohai::Config[:disabled_plugins] is deprecated and will be removed in future releases of ohai. Use ohai.d
isabled_plugins in your configuration file to configure :disabled_plugins for ohai.

This is on Chef v12.5.1 to v12.7.2

rescue in load_current_resource

Using newest aws cookbook, I'm seeing the following:

Recipe: aws::ec2_hints
  * ohai_hint[ec2] action create/var/chef/cache/cookbooks/ohai/providers/hint.rb:31:in `rescue in load_current_resource'
/var/chef/cache/cookbooks/ohai/providers/hint.rb:28:in `load_current_resource'
/var/chef/cache/cookbooks/aws/recipes/ec2_hints.rb:22:in `from_file'
/var/chef/cache/cookbooks/gz-consul/recipes/aws.rb:13:in `from_file'
/var/chef/cache/cookbooks/gz-consul/recipes/default.rb:51:in `from_file'
/var/chef/cache/cookbooks/gz-dns/recipes/consul.rb:18:in `from_file'
/var/chef/cache/cookbooks/gz-dns/recipes/consul_hosts_getter.rb:10:in `from_file'
/var/chef/cache/cookbooks/gz-dns/recipes/default.rb:12:in `from_file'
/var/chef/cache/cookbooks/gz-common/recipes/dns.rb:10:in `from_file'
/var/chef/cache/cookbooks/gz-common/recipes/default.rb:19:in `from_file'
/var/chef/cache/cookbooks/gz-elastic-role/recipes/default.rb:10:in `from_file'
/var/chef/cache/cookbooks/gz-elastic-role/recipes/main.rb:13:in `from_file'
/opt/chef/embedded/lib/ruby/2.1.0/forwardable.rb:183:in `setup_run_context'
/opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.6.0/bin/chef-client:26:in `<top (required)>'
/usr/bin/chef-client:54:in `load'
/usr/bin/chef-client:54:in `<main>'
 (up to date)
  * ohai[reload] action reload
    - re-run ohai and merge results into node attributes

Looks it's a warning for Chef 13:

Deprecated features used!
  content nil currently does not overwrite the value of content. This will change in Chef 13, and the value will be set to nil instead. Please change your code to explicitly accept nil using "property :content, [MyType, nil]", or stop setting this value to nil. at 1 location:
    - /var/chef/cache/cookbooks/ohai/providers/hint.rb:31:in `rescue in load_current_resource'

AMZ linux and chef 13 ohai hints issue

Cookbook version

5.0.3

Chef-client version

13.0.118

Platform Details

chef_version=13.0.118
�[0m platform=amazon
�[0m platform_version=2016.09
�[0m ruby=ruby 2.4.

Scenario:

aws ec2 hints in ohai convergence

Steps to Reproduce:

using deployment script from AWS OPSworks for Chef Automate on Elastic Beanstalk instance with wrapper cookbook in run list to install aws cookbook and run ec2 hints.

Expected Result:

converged instance

Actual Result:

Application update failed at 2017-04-19T15:29:23Z with exit status 1 and error: container_command ebInit in .ebextensions/justChef.config failed.

+ CHEF_DIR=/etc/chef
+ CHEF_CA_PATH=/etc/chef/trusted_certs/opsworks-cm-ca-2016-root.pem
+ CHEF_COMMAND=chef-client
+ ASSOCIATION_PATH=/etc/chef/already_associated_when_this_file_present
+ echo 'Requesting association'
Requesting association
++ associate_node
++ '[' '!' -f /etc/chef/already_associated_when_this_file_present ']'
++ client_key=/etc/chef/client.pem
++ mkdir /etc/chef
++ umask 077
++ openssl genrsa -out /etc/chef/client.pem 2048
Generating RSA private key, 2048 bit long modulus
.......................................................................................................+++
..................+++
unable to write 'random state'
e is 65537 (0x10001)
+++ openssl rsa -in /etc/chef/client.pem -pubout
writing RSA key
++ aws_cli associate-node --node-name i-037a2ab789ac41b8c --engine-attributes Name=CHEF_ORGANIZATION,Value=default 'Name=CHEF_NODE_PUBLIC_KEY,Value='\''-----BEGIN PUBLIC KEY-----
****Scrubbed****
-----END PUBLIC KEY-----'\'''
++ aws opsworks-cm --region us-west-2 --output text associate-node --node-name i-037a2ab789ac41b8c --engine-attributes Name=CHEF_ORGANIZATION,Value=default 'Name=CHEF_NODE_PUBLIC_KEY,Value='\''-----BEGIN PUBLIC KEY-----
****Scrubbed*****
-----END PUBLIC KEY-----'\''' --server-name chef-automate
+ node_association_status_token=Aaan3zdrag3m+OoxSXYhT4kPYcNtlBMN3eNV8BrF3E3aE+no0R131SgfQzungv417L107B7NrmmWBzP7lbktUxo=
+ install_chef_client
+ command -v chef-client
+ '[' '!' 1 -eq 0 ']'
+ echo 'Installing Chef client...'
Installing Chef client...
+ bash -s -- -v ''
+ curl --silent --show-error --retry 3 --location https://omnitruck.chef.io/install.sh
el 6 x86_64
Getting information for chef stable for el...
downloading https://omnitruck.chef.io/stable/chef/metadata?v=&p=el&pv=6&m=x86_64
to file /tmp/install.sh.4499/metadata.txt
trying wget...
sha1	b92640edfce4b23788cfc6e201e862f985ed6873
sha256	aa47e3da21416091e5cb80fd5a8e9172bc7971a228b522871d7276c915116d2f
url	https://packages.chef.io/files/stable/chef/13.0.118/el/6/chef-13.0.118-1.el6.x86_64.rpm
version	13.0.118
downloaded metadata file looks valid...
downloading https://packages.chef.io/files/stable/chef/13.0.118/el/6/chef-13.0.118-1.el6.x86_64.rpm
to file /tmp/install.sh.4499/chef-13.0.118-1.el6.x86_64.rpm
trying wget...
Comparing checksum with sha256sum...

WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING

You are installing an omnibus package without a version pin. If you are installing
on production servers via an automated process this is DANGEROUS and you will
be upgraded without warning on new releases, even to new major releases.
Letting the version float is only appropriate in desktop, test, development or
CI/CD environments.

WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING

Installing chef
installing with rpm...
warning: /tmp/install.sh.4499/chef-13.0.118-1.el6.x86_64.rpm: Header V4 DSA/SHA1 Signature, key ID 83ef826a: NOKEY
Preparing... ########################################
Updating / installing...
chef-13.0.118-1.el6 ########################################
Thank you for installing Chef!
+ echo Installed
Installed
+ write_chef_config
+ config_path=/etc/chef/client.rb
+ '[' '!' -f /etc/chef/client.rb ']'
+ echo 'Writing Chef config...'
Writing Chef config...
+ echo 'chef_server_url '\''https://chef-automate-example.us-west-2.opsworks-cm.io/organizations/default'\'''
+ echo 'node_name '\''i-037a2ab789ac41b8c'\'''
+ key_path=/etc/chef/encrypted_data_bag_secret
+ '[' '!' -f /etc/chef/encrypted_data_bag_secret ']'
+ echo 
****Scrubbed*****
+ install_trusted_certs
+ '[' '!' -f /etc/chef/trusted_certs/opsworks-cm-ca-2016-root.pem ']'
++ dirname /etc/chef/trusted_certs/opsworks-cm-ca-2016-root.pem
+ mkdir -p /etc/chef/trusted_certs
+ echo 'Downloading trusted certs'
Downloading trusted certs
+ curl --silent --show-error --retry 3 --location --output /etc/chef/trusted_certs/opsworks-cm-ca-2016-root.pem https://opsworks-cm-us-west-2-prod-default-assets.s3.amazonaws.com/misc/opsworks-cm-ca-2016-root.pem
+ wait_node_associated Aaan3zdrag3m+OoxSXYhT4kPYcNtlBMN3eNV8BrF3E3aE+no0R131SgfQzungv417L107B7NrmmWBzP7lbktUxo=
+ '[' '!' -f /etc/chef/already_associated_when_this_file_present ']'
+ echo 'Awaiting association...'
Awaiting association...
+ aws_cli wait node-associated --node-association-status-token Aaan3zdrag3m+OoxSXYhT4kPYcNtlBMN3eNV8BrF3E3aE+no0R131SgfQzungv417L107B7NrmmWBzP7lbktUxo=
+ aws opsworks-cm --region us-west-2 --output text wait node-associated --node-association-status-token Aaan3zdrag3m+OoxSXYhT4kPYcNtlBMN3eNV8BrF3E3aE+no0R131SgfQzungv417L107B7NrmmWBzP7lbktUxo= --server-name chef-automate
+ echo Associatied
Associatied
+ touch /etc/chef/already_associated_when_this_file_present
+ chef-client -r 'role[base-amz-linux]' -E base-amz-linux-dev
Starting Chef Client, version 13.0.118�[0m
[2017-04-19T15:29:18+00:00] WARN: Plugin Network: unable to detect ipaddress
resolving cookbooks for run list: ["role-base-amz-linux-nativex"]�[0m
Synchronizing Cookbooks:�[0m
- line (0.6.3)�[0m
- motd (0.6.4)�[0m
- chef-sugar (3.4.0)�[0m
- nano (1.0.3)�[0m
- compat_resource (12.16.3)�[0m
- dstat (0.1.1)�[0m
- sshd (1.3.0)�[0m
- vim (2.0.2)�[0m
- hostsfile (2.4.5)�[0m
- logrotate (2.1.0)�[0m
- sudo (3.3.1)�[0m
- yum-epel (2.1.1)�[0m
- bash-completion (0.1.0)�[0m
- snmp (4.0.0)�[0m
- nfs (2.3.1)�[0m
- ssh_authorized_keys (0.3.0)�[0m
- mingw (2.0.0)�[0m
- now (1.0.0)�[0m
- seven_zip (2.0.2)�[0m
- sysctl (0.8.1)�[0m
- collectd-ng (2.2.0)�[0m
- aws (5.0.0)�[0m
- aws-tagging-nativex (1.1.4)�[0m
- chef_handler (2.1.1)�[0m
- lvm (4.0.6)�[0m
- chef_client_updater (1.0.2)�[0m
- ohai (5.0.3)�[0m
- windows (3.0.5)�[0m
- ephemeral_lvm-nativex (1.0.6)�[0m
- autofs-nativex (1.1.4)�[0m
- iptables (4.1.0)�[0m
- mlocate-nativex (1.0.3)�[0m
- ntp-nativex (1.1.3)�[0m
- ohai-nativex (1.0.5)�[0m
- postfix-nativex (1.0.3)�[0m
- ssh-authorized-keys-nativex (1.0.3)�[0m
- ephemeral_lvm (3.0.1)�[0m
- cron (4.1.1)�[0m
- solarwinds-nativex (1.5.3)�[0m
- graphite-nativex (1.1.6)�[0m
- timezone-ii (0.2.0)�[0m
- ad-nativex (3.3.6)�[0m
- autopatch-nativex (1.3.6)�[0m
- build-essential (8.0.1)�[0m
- chef-client (8.0.1)�[0m
- timezone-nativex (1.0.5)�[0m
- auto-patch (0.1.10)�[0m
- role-base-amz-linux-nativex (1.2.4)�[0m
- hostname-nativex (1.0.8)�[0m
Installing Cookbook Gems:�[0m
Compiling Cookbooks...�[0m
/var/chef/cache/cookbooks/hostsfile/resources/entry.rb:35: warning: constant ::Fixnum is deprecated
Recipe: aws::ec2_hints�[0m
* ohai_hint[ec2] action create
* directory[/etc/chef/ohai/hints] action create
�[32m- create new directory /etc/chef/ohai/hints�[0m�[0m
================================================================================�[0m
�[31mError executing action `create` on resource 'directory[/etc/chef/ohai/hints]'�[0m
================================================================================�[0m

�[0m NoMethodError�[0m
-------------�[0m
undefined method `split' for nil:NilClass�[0m

�[0m Cookbook Trace:�[0m
---------------�[0m
/var/chef/cache/cookbooks/ohai/resources/hint.rb:53:in `block in after_created'
�[0m /var/chef/cache/cookbooks/ohai/resources/hint.rb:52:in `each'
�[0m /var/chef/cache/cookbooks/ohai/resources/hint.rb:52:in `after_created'
�[0m /var/chef/cache/cookbooks/aws/recipes/ec2_hints.rb:20:in `from_file'
�[0m /var/chef/cache/cookbooks/role-base-amz-linux-nativex/recipes/default.rb:152:in `from_file'�[0m

�[0m Resource Declaration:�[0m
---------------------�[0m
# In /var/chef/cache/cookbooks/ohai/resources/hint.rb
�[0m
�[0m 6: directory ::Ohai::Config.ohai.hints_path.first do
�[0m 7: action :create
�[0m 8: recursive true
�[0m 9: end
�[0m 10:
�[0m
�[0m Compiled Resource:�[0m
------------------�[0m
# Declared in /var/chef/cache/cookbooks/ohai/resources/hint.rb:6:in `block in class_from_file'
�[0m
�[0m directory("/etc/chef/ohai/hints") do
�[0m action [:create]
�[0m default_guard_interpreter :default
�[0m path "/etc/chef/ohai/hints"
�[0m recursive true
�[0m declared_type :directory
�[0m cookbook_name "aws"
�[0m owner nil
�[0m group nil
�[0m mode nil
�[0m end
�[0m
�[0m System Info:�[0m
------------�[0m
chef_version=13.0.118
�[0m platform=amazon
�[0m platform_version=2016.09
�[0m ruby=ruby 2.4.

Command output has been truncated. Please see logs for more details.
Incorrect application version "justChef_0.0.1.1" (deployment 2). Expected version "0.0.31" (deployment 1).
Feedback
English
Terms of UsePrivacy Policy© 2008 - 2017, Amazon Web Services, Inc. or its affiliates. All rights reserved.

error executing ohai_plugin

I am using the latest ohai cookbook. Here is my code
ohai_plugin 'My Ohai Plugin' do
name 's1'
path '/var/chefworkstation/ohai_plugins'
end

I am not sure why I am getting the following error:
Error executing action create on resource 'cookbook_file[/var/chefworkstation/ohai_plugins/s1.rb]'

missing node attributes

Cookbook version

Latest

Chef-client version

12.15.19

Platform Details

Linux

Here is my code:
File ol_ohai_plugin.rb has the following content

Ohai.plugin(:ol_ohai_plugin) do
  provides "oci_ol_km"
  collect_data(:default) do
    oci_ol_km Mash.new
    oci_ol_km[:ipaddress]="127.0.0.1"
  end
end

File - recipes/ol_translator.rb

`require 'json'

ohai_plugin 'My Ohai Plugin' do
  name 'ol_ohai_plugin'
  path '/var/tmp'
end

puts "**********************************"
puts node[:oci_ol_km][:ipaddress]
puts "**********************************"

`
When I run this code from my workstation on a node 'node10', I am not seeing my node attributes populated in the node object under 'automatic'.

From my workstation, I run it as follows:
knife ssh ip_address_of_node_10 'chef-client'
Please let me know what am I missing

Plugin_path configuration issue with custom plugins

Cookbook version

= 4.0

Chef-client version

12.8

Platform Details

CentOS 7.2 / Windows Server 2012R2

Scenario:

I'm trying to define an ohai plugin, but also use its values in my attributes file.

Steps to Reproduce:

my_cookbook/attributes/default.rb

default['my_cookbook'] # autovivify
if node['my_cookbook']['ohai']
  default['my_cookbook']['ohai']['ultra_important_attribute'] = 'OK'
else
  ::Chef::Log.warn 'my_cookbook.ohai is not available, maybe next run?'
end

my_cookbook/recipes/default.rb

ohai_plugin 'my_custom_plugin'

my_cookbook/files/default/my_custom_plugin.rb

Ohai.plugin(:MyCookbookOhai) do
  provides 'my_cookbook/ohai/ultra_important_attribute'
  collect_data do
    my_cookbook['ohai'] = Mash.new(ultra_important_attribute: :ultra_important)
  end
end

Expected Result:

At first run I expect to get the unavailable warning; but at 2nd run I should normally have access to my ultra important attribute.

Actual Result:

Even using the compile_time property of the ohai_plugin resource, my attribute is not accessible from attributes file.

       [2016-12-07T16:07:02+00:00] WARN: my_cookbook.ohai is not available, maybe next run?
       Recipe: my_cookbook::default
         * ohai_plugin[my_custom_plugin] action create
       [2016-12-07T16:07:02+00:00] WARN: The Ohai plugin_path does not include /tmp/kitchen/ohai/plugins. 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.
       [2016-12-07T16:07:02+00:00] WARN: Adding /tmp/kitchen/ohai/plugins to the Ohai plugin path for this chef-client run only

I know that I'm able to change the ohai.plugin path using chef-client cookbook, but a simple cookbook maintainer I don't want to change my user's configuration.

What do you suggest?
IMHO the present ohai cookbook should be responsible of Ohai configuration see chef/ohai#919

Regards.

Cc. @aboten

Ohai 4.0.1 error on windows.

Cookbook version

4.01

Chef-client version

12.10.24

Platform Details

AWS Windows 2012R2

Scenario:

Install ohai plugin. Everything works for linux but not windows. Looks to be due to the declared root owner and group not existing on windows for the ohai_plugin resource file creation.

Steps to Reproduce:

create ohai plugin on windows 2012r2

Expected Result:

aws plugin created to collect region attribute based on the ec2 placement zone attribute. This was working on 3.x versions of ohai. After ohai upgraded to 4.x I updated our plugin to match new resource syntax. This worked on linux servers but am now getting this error below on windows servers.

Actual Result:

Error:

<Chef::Exceptions::Win32APIError: ohai_plugin[aws] (ohai-nativex::awsplugin line 17) had an error: Chef::Exceptions::Win32APIError: cookbook_file[C:/chef/ohai/plugins/aws.rb] (C:/chef/cache/cookbooks/ohai/resources/plugin.rb line 76) had an error: Chef::Exceptions::Win32APIError: No mapping between account names and security IDs was done. ---- Begin Win32 API output ---- System Error Code: 1332 System Error Message: No mapping between account names and security IDs was done. ---- End Win32 API output ---- > had an error:

ohai_plugin[aws](ohai-nativex::awsplugin line 17) had an error: Chef::Exceptions::Win32APIError: cookbook_file[C:/chef/ohai/plugins/aws.rb](C:/chef/cache/cookbooks/ohai/resources/plugin.rb line 76) had an error: Chef::Exceptions::Win32APIError: No mapping between account names and security IDs was done. ---- Begin Win32 API output ---- System Error Code: 1332 System Error Message: No mapping between account names and security IDs was done. ---- End Win32 API output ----
Description: Error executing action create on resource 'ohai_plugin[aws]'
Chef::Exceptions::Win32APIError
cookbook_file[C:/chef/ohai/plugins/aws.rb](C:/chef/cache/cookbooks/ohai/resources/plugin.rb line 76) had an error: Chef::Exceptions::Win32APIError: No mapping between account names and security IDs was done.
---- Begin Win32 API output ----
System Error Code: 1332
System Error Message: No mapping between account names and security IDs was done.
---- End Win32 API output ----
Resource Declaration:

In C:/chef/cache/cookbooks/ohai-nativex/recipes/awsplugin.rb

17: ohai_plugin 'aws' do
18: notifies :reload, 'ohai[reload_aws]', :immediately
19: end
20:
Compiled Resource:

Declared in C:/chef/cache/cookbooks/ohai-nativex/recipes/awsplugin.rb:17:in `from_file'

ohai_plugin("aws") do
action [:create]
retries 0
retry_delay 2
default_guard_interpreter :default
declared_type :ohai_plugin
cookbook_name "ohai-nativex"
recipe_name "awsplugin"
compile_time true
plugin_name "aws"
end
Stacktrace
C:/opscode/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.10.24-universal-mingw32/lib/chef/win32/error.rb:81:in raise!' C:/opscode/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.10.24-universal-mingw32/lib/chef/win32/security.rb:383:inlookup_account_name'
C:/opscode/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.10.24-universal-mingw32/lib/chef/win32/security/sid.rb:44:in from_account' C:/opscode/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.10.24-universal-mingw32/lib/chef/file_access_control/windows.rb:112:inget_sid'
C:/opscode/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.10.24-universal-mingw32/lib/chef/file_access_control/windows.rb:331:in target_owner' C:/opscode/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.10.24-universal-mingw32/lib/chef/file_access_control/windows.rb:300:intarget_dacl'
C:/opscode/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.10.24-universal-mingw32/lib/chef/file_access_control/windows.rb:132:in should_update_dacl?' C:/opscode/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.10.24-universal-mingw32/lib/chef/file_access_control/windows.rb:63:inrequires_changes?'
C:/opscode/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.10.24-universal-mingw32/lib/chef/provider/file.rb:449:in do_acl_changes' C:/opscode/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.10.24-universal-mingw32/lib/chef/provider/file.rb:155:inaction_create'
C:/opscode/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.10.24-universal-mingw32/lib/chef/provider.rb:145:in run_action' C:/opscode/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.10.24-universal-mingw32/lib/chef/resource.rb:596:inrun_action'
C:/chef/cache/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/runner.rb:41:in run_action' C:/opscode/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.10.24-universal-mingw32/lib/chef/runner.rb:97:inblock (2 levels) in converge'
C:/opscode/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.10.24-universal-mingw32/lib/chef/runner.rb:97:in each' C:/opscode/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.10.24-universal-mingw32/lib/chef/runner.rb:97:inblock in converge'
C:/opscode/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.10.24-universal-mingw32/lib/chef/resource_collection/resource_list.rb:94:in block in execute_each_resource' C:/opscode/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.10.24-universal-mingw32/lib/chef/resource_collection/stepable_iterator.rb:116:incall'
C:/opscode/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.10.24-universal-mingw32/lib/chef/resource_collection/stepable_iterator.rb:116:in call_iterator_block' C:/opscode/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.10.24-universal-mingw32/lib/chef/resource_collection/stepable_iterator.rb:85:instep'
C:/opscode/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.10.24-universal-mingw32/lib/chef/resource_collection/stepable_iterator.rb:104:in iterate' C:/opscode/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.10.24-universal-mingw32/lib/chef/resource_collection/stepable_iterator.rb:55:ineach_with_index'
C:/opscode/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.10.24-universal-mingw32/lib/chef/resource_collection/resource_list.rb:92:in execute_each_resource' C:/opscode/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.10.24-universal-mingw32/lib/chef/runner.rb:96:inconverge'
C:/chef/cache/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/provider.rb:125:in compile_and_converge_action' (eval):2:inaction_create'
C:/opscode/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.10.24-universal-mingw32/lib/chef/provider.rb:145:in run_action' C:/opscode/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.10.24-universal-mingw32/lib/chef/resource.rb:596:inrun_action'
C:/chef/cache/cookbooks/ohai/resources/plugin.rb:114:in block in after_created' C:/chef/cache/cookbooks/ohai/resources/plugin.rb:113:ineach'
C:/chef/cache/cookbooks/ohai/resources/plugin.rb:113:in after_created' C:/opscode/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.10.24-universal-mingw32/lib/chef/resource_builder.rb:92:inbuild'
C:/opscode/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.10.24-universal-mingw32/lib/chef/dsl/declare_resource.rb:277:in build_resource' C:/opscode/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.10.24-universal-mingw32/lib/chef/dsl/declare_resource.rb:234:indeclare_resource'
C:/opscode/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.10.24-universal-mingw32/lib/chef/dsl/resources.rb:40:in ohai_plugin' C:/chef/cache/cookbooks/ohai-nativex/recipes/awsplugin.rb:17:infrom_file'
C:/opscode/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.10.24-universal-mingw32/lib/chef/mixin/from_file.rb:30:in instance_eval' C:/opscode/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.10.24-universal-mingw32/lib/chef/mixin/from_file.rb:30:infrom_file'
C:/opscode/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.10.24-universal-mingw32/lib/chef/cookbook_version.rb:233:in load_recipe' C:/opscode/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.10.24-universal-mingw32/lib/chef/run_context.rb:354:inload_recipe'
C:/opscode/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.10.24-universal-mingw32/lib/chef/run_context.rb:310:in block in include_recipe' C:/opscode/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.10.24-universal-mingw32/lib/chef/run_context.rb:309:ineach'
C:/opscode/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.10.24-universal-mingw32/lib/chef/run_context.rb:309:in include_recipe' C:/opscode/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.10.24-universal-mingw32/lib/chef/dsl/include_recipe.rb:26:ininclude_recipe'
C:/chef/cache/cookbooks/ohai-nativex/recipes/default.rb:10:in from_file' C:/opscode/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.10.24-universal-mingw32/lib/chef/mixin/from_file.rb:30:ininstance_eval'
C:/opscode/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.10.24-universal-mingw32/lib/chef/mixin/from_file.rb:30:in from_file' C:/opscode/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.10.24-universal-mingw32/lib/chef/cookbook_version.rb:233:inload_recipe'
C:/opscode/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.10.24-universal-mingw32/lib/chef/run_context.rb:354:in load_recipe' C:/opscode/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.10.24-universal-mingw32/lib/chef/run_context.rb:310:inblock in include_recipe'
C:/opscode/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.10.24-universal-mingw32/lib/chef/run_context.rb:309:in each' C:/opscode/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.10.24-universal-mingw32/lib/chef/run_context.rb:309:ininclude_recipe'
C:/opscode/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.10.24-universal-mingw32/lib/chef/dsl/include_recipe.rb:26:in include_recipe' C:/chef/cache/cookbooks/role-base-windows-nativex/recipes/default.rb:22:infrom_file'
C:/opscode/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.10.24-universal-mingw32/lib/chef/mixin/from_file.rb:30:in instance_eval' C:/opscode/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.10.24-universal-mingw32/lib/chef/mixin/from_file.rb:30:infrom_file'
C:/opscode/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.10.24-universal-mingw32/lib/chef/cookbook_version.rb:233:in load_recipe' C:/opscode/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.10.24-universal-mingw32/lib/chef/run_context.rb:354:inload_recipe'
C:/opscode/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.10.24-universal-mingw32/lib/chef/run_context.rb:310:in block in include_recipe' C:/opscode/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.10.24-universal-mingw32/lib/chef/run_context.rb:309:ineach'
C:/opscode/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.10.24-universal-mingw32/lib/chef/run_context.rb:309:in include_recipe' C:/opscode/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.10.24-universal-mingw32/lib/chef/dsl/include_recipe.rb:26:ininclude_recipe'
C:/chef/cache/cookbooks/role-mssql-nativex/recipes/default.rb:15:in from_file' C:/opscode/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.10.24-universal-mingw32/lib/chef/mixin/from_file.rb:30:ininstance_eval'
C:/opscode/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.10.24-universal-mingw32/lib/chef/mixin/from_file.rb:30:in from_file' C:/opscode/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.10.24-universal-mingw32/lib/chef/cookbook_version.rb:233:inload_recipe'
C:/opscode/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.10.24-universal-mingw32/lib/chef/run_context.rb:354:in load_recipe' C:/opscode/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.10.24-universal-mingw32/lib/chef/run_context/cookbook_compiler.rb:140:inblock in compile_recipes'
C:/opscode/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.10.24-universal-mingw32/lib/chef/run_context/cookbook_compiler.rb:138:in each' C:/opscode/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.10.24-universal-mingw32/lib/chef/run_context/cookbook_compiler.rb:138:incompile_recipes'
C:/opscode/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.10.24-universal-mingw32/lib/chef/run_context/cookbook_compiler.rb:75:in compile' C:/opscode/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.10.24-universal-mingw32/lib/chef/run_context.rb:176:inload'
C:/opscode/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.10.24-universal-mingw32/lib/chef/policy_builder/expand_node_object.rb:97:in setup_run_context' C:/opscode/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.10.24-universal-mingw32/lib/chef/client.rb:508:insetup_run_context'
C:/opscode/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.10.24-universal-mingw32/lib/chef/client.rb:278:in run' C:/opscode/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.10.24-universal-mingw32/lib/chef/application.rb:267:inrun_with_graceful_exit_option'
C:/opscode/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.10.24-universal-mingw32/lib/chef/application.rb:243:in block in run_chef_client' C:/opscode/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.10.24-universal-mingw32/lib/chef/local_mode.rb:44:inwith_server_connectivity'
C:/opscode/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.10.24-universal-mingw32/lib/chef/application.rb:226:in run_chef_client' C:/opscode/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.10.24-universal-mingw32/lib/chef/application/client.rb:419:inrun_application'
C:/opscode/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.10.24-universal-mingw32/lib/chef/application.rb:58:in run' C:/opscode/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.10.24-universal-mingw32/bin/chef-client:26:in<top (required)>'
C:/opscode/chef/bin/chef-client:61:in load' C:/opscode/chef/bin/chef-client:61:in

'

Getting undefined local variable or method when using `ohai` cookbook with chef 14

Cookbook version

5.2

Chef-client version

provisioner:
  name: chef_zero
  product_name: chef
  product_version: 14
  install_strategy: always
  deprecation_as_error: true
  client_rb:
    Ohai::Config[:directory] =: '/etc/chef/ohai_plugins'

Platform Details

rhel69

Scenario:

[What you are trying to achieve and you can't?]

Steps to Reproduce:

Add ohai-5.2 into metadata.rb as a denepdency. Then use ohai_plugin '<plugin_name>' resource which will throw this error.

Expected Result:

It should converge successfully by creating ohai_plugin

Actual Result:

https://gist.github.com/snehitgajjar/6c47fe3efb552ce9244f2aae87271ea0

receiving multiple warnings

Running Rspec/ ChefSpec, i'm getting spammed with the following Warning for each example"

WARN: Ohai::Config[:plugin_path] is set. Ohai::Config[:plugin_path] is deprecated and will be removed in future releases of ohai. Use ohai.plugin_path in your configuration file to configure :plugin_path for ohai.

This happens with any cookbook, which depends on the ohai cookbook (directly or down the chain), so it does not 'appear' to be specific to my code.

chefdk- 0.10
ohai cookbook - 2.0.4
Oracle Linux 6.5
chefspec - 4.4.0

Support for an empty content?

Right now if you don't supply a content the .json file isn't created. Is this intentional? For now I have to put some garbage key in my content for an ec2.json to be created since vpc instances aren't detected automatically.

chefspec tests broken

Started getting this after the 3.0.0 release in any of our internal wrapper cookbooks that include ohai in the dependency tree.

================================================================================
Recipe Compile Error in /tmp/d20160314-459-1k4mp83/cookbooks/ohai/libraries/matchers.rb
================================================================================

NoMethodError
-------------
undefined method `define_runner_method' for ChefSpec:Module

Cookbook Trace:
---------------
  /tmp/d20160314-459-1k4mp83/cookbooks/ohai/libraries/matchers.rb:4:in `<top (required)>'

Relevant File Content:
----------------------
/tmp/d20160314-459-1k4mp83/cookbooks/ohai/libraries/matchers.rb:

  1:  # encoding: utf-8
  2:
  3:  if defined?(ChefSpec)
  4>>   ChefSpec.define_runner_method(:ohai_hint)
  5:
  6:    def create_ohai_hint(resource)
  7:      ChefSpec::Matchers::ResourceMatcher.new(:ohai_hint, :create, resource)
  8:    end
  9:
 10:    def delete_ohai_hint(resource)
 11:      ChefSpec::Matchers::ResourceMatcher.new(:ohai_hint, :delete, resource)
 12:    end
 13:  end

on chefdk 0.11.2

Thanks,
-Bill

ohai plugin_path logic doesn't work with Chef local mode

Cookbook version

4.2.3

Chef-client version

12.17.44

Platform Details

Windows 2012 R2 - AWS

Scenario:

I am trying to install IIS with iis cookbook (5.0.5)
depends on windows cookbook (2.1.1)

Steps to Reproduce:

recipes/default.rb

include_recipe 'iis::mod_aspnet45'
include_recipe 'iis::remove_default_site'

Expected Result:

Expected to install IIS

Actual Result:

End with the error message

[2016-12-18T20:08:33+00:00] INFO: Processing windows_feature[IIS-WebServerRole] action install (iis::default line 25)
[2016-12-18T20:08:33+00:00] INFO: node['dism_features'] data missing. Installing the dism_features Ohai plugin
[2016-12-18T20:08:33+00:00] INFO: Processing ohai_plugin[dism_features] action create (C:/Windows/system32/config/systemprofile/.chef/local-mode-cache/cache/cookbooks/windows/providers/feature_dism.rb line 79)
[2016-12-18T20:08:33+00:00] 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
[2016-12-18T20:08:33+00:00] INFO: Running queued delayed notifications before re-raising exception
[2016-12-18T20:08:33+00:00] ERROR: Running exception handlers
[2016-12-18T20:08:33+00:00] ERROR: Exception handlers complete
[2016-12-18T20:08:33+00:00] FATAL: Stacktrace dumped to C:/Windows/system32/config/systemprofile/.chef/local-mode-cache/cache/chef-stacktrace.out
[2016-12-18T20:08:33+00:00] FATAL: Please provide the contents of the stacktrace.out file if you file a bug report

chef-stacktrace.out

Generated at 2016-12-18 20:16:16 +0000
SystemExit: windows_feature[IIS-WebServerRole] (iis::default line 25) had an error: SystemExit: ohai_plugin[dism_features] (C:/Windows/system32/config/systemprofile/.chef/local-mode-cache/cache/cookbooks/windows/providers/feature_dism.rb line 79) had an error: SystemExit: exit
C:/opscode/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.17.44-universal-mingw32/lib/chef/application.rb:367:in `exit'
C:/opscode/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.17.44-universal-mingw32/lib/chef/application.rb:367:in `fatal!'
C:/Windows/system32/config/systemprofile/.chef/local-mode-cache/cache/cookbooks/ohai/resources/plugin.rb:25:in `chef_config_path'
C:/Windows/system32/config/systemprofile/.chef/local-mode-cache/cache/cookbooks/ohai/resources/plugin.rb:33:in `ohai_plugin_path'
C:/Windows/system32/config/systemprofile/.chef/local-mode-cache/cache/cookbooks/ohai/resources/plugin.rb:16:in `desired_plugin_path'
C:/Windows/system32/config/systemprofile/.chef/local-mode-cache/cache/cookbooks/ohai/resources/plugin.rb:80:in `block in class_from_file'
(eval):2:in `block in action_create'
C:/opscode/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.17.44-universal-mingw32/lib/chef/provider.rb:361:in `instance_eval'
C:/opscode/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.17.44-universal-mingw32/lib/chef/provider.rb:361:in `compile_and_converge_action'
(eval):2:in `action_create'
C:/opscode/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.17.44-universal-mingw32/lib/chef/provider.rb:145:in `run_action'
C:/opscode/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.17.44-universal-mingw32/lib/chef/resource.rb:622:in `run_action'
C:/Windows/system32/config/systemprofile/.chef/local-mode-cache/cache/cookbooks/ohai/resources/plugin.rb:131:in `block in after_created'
C:/Windows/system32/config/systemprofile/.chef/local-mode-cache/cache/cookbooks/ohai/resources/plugin.rb:130:in `each'
C:/Windows/system32/config/systemprofile/.chef/local-mode-cache/cache/cookbooks/ohai/resources/plugin.rb:130:in `after_created'
C:/opscode/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.17.44-universal-mingw32/lib/chef/resource_builder.rb:92:in `build'
C:/opscode/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.17.44-universal-mingw32/lib/chef/dsl/declare_resource.rb:291:in `build_resource'
C:/opscode/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.17.44-universal-mingw32/lib/chef/dsl/declare_resource.rb:248:in `declare_resource'
C:/opscode/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.17.44-universal-mingw32/lib/chef/dsl/resources.rb:40:in `ohai_plugin'
C:/Windows/system32/config/systemprofile/.chef/local-mode-cache/cache/cookbooks/windows/providers/feature_dism.rb:79:in `install_ohai_plugin'
C:/Windows/system32/config/systemprofile/.chef/local-mode-cache/cache/cookbooks/windows/providers/feature_dism.rb:53:in `installed?'
C:/Windows/system32/config/systemprofile/.chef/local-mode-cache/cache/cookbooks/windows/libraries/feature_base.rb:6:in `action_install'
C:/opscode/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.17.44-universal-mingw32/lib/chef/provider.rb:145:in `run_action'
C:/opscode/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.17.44-universal-mingw32/lib/chef/resource.rb:622:in `run_action'
C:/opscode/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.17.44-universal-mingw32/lib/chef/runner.rb:69:in `run_action'
C:/opscode/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.17.44-universal-mingw32/lib/chef/runner.rb:97:in `block (2 levels) in converge'
C:/opscode/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.17.44-universal-mingw32/lib/chef/runner.rb:97:in `each'
C:/opscode/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.17.44-universal-mingw32/lib/chef/runner.rb:97:in `block in converge'
C:/opscode/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.17.44-universal-mingw32/lib/chef/resource_collection/resource_list.rb:94:in `block in execute_each_resource'
C:/opscode/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.17.44-universal-mingw32/lib/chef/resource_collection/stepable_iterator.rb:114:in `call_iterator_block'
C:/opscode/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.17.44-universal-mingw32/lib/chef/resource_collection/stepable_iterator.rb:85:in `step'
C:/opscode/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.17.44-universal-mingw32/lib/chef/resource_collection/stepable_iterator.rb:103:in `iterate'
C:/opscode/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.17.44-universal-mingw32/lib/chef/resource_collection/stepable_iterator.rb:55:in `each_with_index'
C:/opscode/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.17.44-universal-mingw32/lib/chef/resource_collection/resource_list.rb:92:in `execute_each_resource'
C:/opscode/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.17.44-universal-mingw32/lib/chef/runner.rb:96:in `converge'
C:/opscode/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.17.44-universal-mingw32/lib/chef/client.rb:670:in `block in converge'
C:/opscode/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.17.44-universal-mingw32/lib/chef/client.rb:665:in `catch'
C:/opscode/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.17.44-universal-mingw32/lib/chef/client.rb:665:in `converge'
C:/opscode/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.17.44-universal-mingw32/lib/chef/client.rb:704:in `converge_and_save'
C:/opscode/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.17.44-universal-mingw32/lib/chef/client.rb:284:in `run'
C:/opscode/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.17.44-universal-mingw32/lib/chef/application.rb:276:in `run_with_graceful_exit_option'
C:/opscode/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.17.44-universal-mingw32/lib/chef/application.rb:252:in `block in run_chef_client'
C:/opscode/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.17.44-universal-mingw32/lib/chef/local_mode.rb:44:in `with_server_connectivity'
C:/opscode/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.17.44-universal-mingw32/lib/chef/application.rb:235:in `run_chef_client'
C:/opscode/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.17.44-universal-mingw32/lib/chef/application/client.rb:464:in `sleep_then_run_chef_client'
C:/opscode/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.17.44-universal-mingw32/lib/chef/application/client.rb:451:in `block in interval_run_chef_client'
C:/opscode/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.17.44-universal-mingw32/lib/chef/application/client.rb:450:in `loop'
C:/opscode/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.17.44-universal-mingw32/lib/chef/application/client.rb:450:in `interval_run_chef_client'
C:/opscode/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.17.44-universal-mingw32/lib/chef/application/client.rb:434:in `run_application'
C:/opscode/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.17.44-universal-mingw32/lib/chef/application.rb:59:in `run'
C:/opscode/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.17.44-universal-mingw32/bin/chef-client:26:in `<top (required)>'
C:/opscode/chef/bin/chef-client:68:in `load'
C:/opscode/chef/bin/chef-client:68:in `<main>'

>>>> Caused by SystemExit: exit
C:/opscode/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.17.44-universal-mingw32/lib/chef/application.rb:367:in `exit'
C:/opscode/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.17.44-universal-mingw32/lib/chef/application.rb:367:in `fatal!'
C:/Windows/system32/config/systemprofile/.chef/local-mode-cache/cache/cookbooks/ohai/resources/plugin.rb:25:in `chef_config_path'
C:/Windows/system32/config/systemprofile/.chef/local-mode-cache/cache/cookbooks/ohai/resources/plugin.rb:33:in `ohai_plugin_path'
C:/Windows/system32/config/systemprofile/.chef/local-mode-cache/cache/cookbooks/ohai/resources/plugin.rb:16:in `desired_plugin_path'
C:/Windows/system32/config/systemprofile/.chef/local-mode-cache/cache/cookbooks/ohai/resources/plugin.rb:80:in `block in class_from_file'
(eval):2:in `block in action_create'
C:/opscode/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.17.44-universal-mingw32/lib/chef/provider.rb:361:in `instance_eval'
C:/opscode/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.17.44-universal-mingw32/lib/chef/provider.rb:361:in `compile_and_converge_action'
(eval):2:in `action_create'
C:/opscode/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.17.44-universal-mingw32/lib/chef/provider.rb:145:in `run_action'
C:/opscode/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.17.44-universal-mingw32/lib/chef/resource.rb:622:in `run_action'
C:/Windows/system32/config/systemprofile/.chef/local-mode-cache/cache/cookbooks/ohai/resources/plugin.rb:131:in `block in after_created'
C:/Windows/system32/config/systemprofile/.chef/local-mode-cache/cache/cookbooks/ohai/resources/plugin.rb:130:in `each'
C:/Windows/system32/config/systemprofile/.chef/local-mode-cache/cache/cookbooks/ohai/resources/plugin.rb:130:in `after_created'
C:/opscode/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.17.44-universal-mingw32/lib/chef/resource_builder.rb:92:in `build'
C:/opscode/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.17.44-universal-mingw32/lib/chef/dsl/declare_resource.rb:291:in `build_resource'
C:/opscode/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.17.44-universal-mingw32/lib/chef/dsl/declare_resource.rb:248:in `declare_resource'
C:/opscode/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.17.44-universal-mingw32/lib/chef/dsl/resources.rb:40:in `ohai_plugin'
C:/Windows/system32/config/systemprofile/.chef/local-mode-cache/cache/cookbooks/windows/providers/feature_dism.rb:79:in `install_ohai_plugin'
C:/Windows/system32/config/systemprofile/.chef/local-mode-cache/cache/cookbooks/windows/providers/feature_dism.rb:53:in `installed?'
C:/Windows/system32/config/systemprofile/.chef/local-mode-cache/cache/cookbooks/windows/libraries/feature_base.rb:6:in `action_install'
C:/opscode/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.17.44-universal-mingw32/lib/chef/provider.rb:145:in `run_action'
C:/opscode/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.17.44-universal-mingw32/lib/chef/resource.rb:622:in `run_action'
C:/opscode/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.17.44-universal-mingw32/lib/chef/runner.rb:69:in `run_action'
C:/opscode/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.17.44-universal-mingw32/lib/chef/runner.rb:97:in `block (2 levels) in converge'
C:/opscode/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.17.44-universal-mingw32/lib/chef/runner.rb:97:in `each'
C:/opscode/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.17.44-universal-mingw32/lib/chef/runner.rb:97:in `block in converge'
C:/opscode/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.17.44-universal-mingw32/lib/chef/resource_collection/resource_list.rb:94:in `block in execute_each_resource'
C:/opscode/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.17.44-universal-mingw32/lib/chef/resource_collection/stepable_iterator.rb:114:in `call_iterator_block'
C:/opscode/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.17.44-universal-mingw32/lib/chef/resource_collection/stepable_iterator.rb:85:in `step'
C:/opscode/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.17.44-universal-mingw32/lib/chef/resource_collection/stepable_iterator.rb:103:in `iterate'
C:/opscode/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.17.44-universal-mingw32/lib/chef/resource_collection/stepable_iterator.rb:55:in `each_with_index'
C:/opscode/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.17.44-universal-mingw32/lib/chef/resource_collection/resource_list.rb:92:in `execute_each_resource'
C:/opscode/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.17.44-universal-mingw32/lib/chef/runner.rb:96:in `converge'
C:/opscode/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.17.44-universal-mingw32/lib/chef/client.rb:670:in `block in converge'
C:/opscode/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.17.44-universal-mingw32/lib/chef/client.rb:665:in `catch'
C:/opscode/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.17.44-universal-mingw32/lib/chef/client.rb:665:in `converge'
C:/opscode/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.17.44-universal-mingw32/lib/chef/client.rb:704:in `converge_and_save'
C:/opscode/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.17.44-universal-mingw32/lib/chef/client.rb:284:in `run'
C:/opscode/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.17.44-universal-mingw32/lib/chef/application.rb:276:in `run_with_graceful_exit_option'
C:/opscode/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.17.44-universal-mingw32/lib/chef/application.rb:252:in `block in run_chef_client'
C:/opscode/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.17.44-universal-mingw32/lib/chef/local_mode.rb:44:in `with_server_connectivity'
C:/opscode/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.17.44-universal-mingw32/lib/chef/application.rb:235:in `run_chef_client'
C:/opscode/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.17.44-universal-mingw32/lib/chef/application/client.rb:464:in `sleep_then_run_chef_client'
C:/opscode/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.17.44-universal-mingw32/lib/chef/application/client.rb:451:in `block in interval_run_chef_client'
C:/opscode/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.17.44-universal-mingw32/lib/chef/application/client.rb:450:in `loop'
C:/opscode/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.17.44-universal-mingw32/lib/chef/application/client.rb:450:in `interval_run_chef_client'
C:/opscode/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.17.44-universal-mingw32/lib/chef/application/client.rb:434:in `run_application'
C:/opscode/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.17.44-universal-mingw32/lib/chef/application.rb:59:in `run'
C:/opscode/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.17.44-universal-mingw32/bin/chef-client:26:in `<top (required)>'
C:/opscode/chef/bin/chef-client:68:in `load'
C:/opscode/chef/bin/chef-client:68:in `<main>'

There is no such error if I use windows cookbook 2.0.2

ohai[reload] executing during every converge

I have a wrapper cookbook using https://github.com/chef-cookbooks/aws with:
include_recipe 'aws::ec2_hints'

The recipe runs and works as expected. But the following is being run every time

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

Chef log shows this:

* ohai[reload] action reload/opt/chef/embedded/lib/ruby/gems/2.1.0/gems/ohai-8.5.0/lib/ohai/plugins/solaris2/network.rb:57: warning: already initialized constant ETHERNET_ENCAPS
       /opt/chef/embedded/lib/ruby/gems/2.1.0/gems/ohai-8.5.0/lib/ohai/plugins/solaris2/network.rb:57: warning: previous definition of ETHERNET_ENCAPS was here

           - re-run ohai and merge results into node attributes

I get the same output on every converge. The OS is Ubuntu 14.04. I'm not sure about the references to solaris2. Is anybody else seeing this output? Any ideas on how to fix this?

Ohai plugin_path comparison does not handle different path separators

Cookbook version

4.2.3

Chef-client version

12.19.36

Platform Details

Windows 7 x64

Scenario:

Set ohai.plugin_path to c:\chef\ohai\plugins using Windows style path separators.

Steps to Reproduce:

Add ohai.plugin_path << 'c:\chef\ohai\plugins' to the client.rb configuration file.

Expected Result:

I expect the configuration value work and not cause warnings.

Actual Result:

Ohai reads the configuration settings and runs the custom plugin(s). When Chef gets to the ohai_plugin resource, it thinks it needs to reload the plugin. That process throws multiple warnings.

INFO: Processing ohai_plugin[my_plugin_1] action create (my_cookbook::default line 12)
WARN: The Ohai plugin_path does not include C:/chef/ohai/plugins. 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.
WARN: Adding C:/chef/ohai/plugins to the Ohai plugin path for this chef-client run only
INFO: Processing directory[C:/chef/ohai/plugins] action create (C:/chef/cache/cookbooks/ohai/resources/plugin.rb line 80)
INFO: Processing cookbook_file[C:/chef/ohai/plugins/my_plugin_1.rb] action create (C:/chef/cache/cookbooks/ohai/resources/plugin.rb line 87)
INFO: Processing ohai[my_plugin_1] action reload (C:/chef/cache/cookbooks/ohai/resources/plugin.rb line 110)
WARN: Plugin Definition Error: <C:/Chef/ohai/plugins/my_plugin_1.rb>: collect_data already defined on platform windows
WARN: Plugin Definition Error: <C:/Chef/ohai/plugins/my_plugin_2.rb>: collect_data already defined on platform windows
WARN: Plugin Definition Error: <C:/Chef/ohai/plugins/my_plugin_3.rb>: collect_data already defined on platform windows
WARN: Plugin Definition Error: <C:/Chef/ohai/plugins/my_plugin_4.rb>: collect_data already defined on platform windows
WARN: Plugin Definition Error: <C:/Chef/ohai/plugins/my_plugin_5.rb>: collect_data already defined on platform windows
WARN: Plugin Definition Error: <C:/Chef/ohai/plugins/my_plugin_6.rb>: collect_data already defined on platform windows
WARN: Plugin Definition Error: <C:/Chef/ohai/plugins/my_plugin_7.rb>: collect_data already defined on platform windows
INFO: ohai[my_plugin_1] reloaded

From what I can tell, when the Ohai cookbook checks to see if a plugin is already in the path, it simply compares strings and does not take into account different types of path separators.

https://github.com/chef-cookbooks/ohai/blob/58b596c7c0d0e6dd15a59d37567bac02bb12c26c/resources/plugin.rb#L50

The simple workaround is to use / as the path separator in client.rb file. The ohai settings documentation does not specific why types of path separators are allowed.

spec_helper.rb

Cookbook version

5.2.5

Chef-client version

14.7.17
Chef Development Kit Version: 3.6.17
chef-client version: 14.7.17
delivery version: master (19553a3799e2b1ebee5f7f5798ddb74fd61603f8)
berks version: 7.0.7
kitchen version: 1.23.3
inspec version: 3.0.61

Platform Details

MacOS X Mojave 10.13.2

Scenario:

My unit tests fail due to deprecation warning related plugin_helper.rb

Steps to Reproduce:

  1. rm -Rf ~/.chef/ohai
  2. chef generate cookbook reduction
  3. cd reduction
  4. echo "depends 'nginx'" >> metadata.rb
  5. berks install
  6. echo "include_recipe 'nginx::source'" > recipes/default.rb
  7. chef exec rspec # See Actual Result :: rspec
  8. ls ~/.chef/ohai/cookbook_plugins/ohai/ # <-- written by ohai cookbook?
  9. ohai # works fine
  10. ohai -d ~/.chef/ohai/cookbook_plugins # See Actual Result :: ohai

Expected Result:

Generated spec tests should return 'converges successfully'.

Actual Result:

rspec

F/opt/chefdk/embedded/lib/ruby/gems/2.5.0/gems/ohai-14.8.10/lib/ohai/plugins/windows/filesystem.rb:26: warning: already initialized constant CONVERSION_STATUS
/opt/chefdk/embedded/lib/ruby/gems/2.5.0/gems/ohai-14.8.10/lib/ohai/plugins/windows/filesystem.rb:26: warning: previous definition of CONVERSION_STATUS was here
F

Failures:

  1) reduction::default When all attributes are default, on Ubuntu 16.04 converges successfully
     Failure/Error: expect { chef_run }.to_not raise_error
     
       expected no Exception, got #<Ohai::Exceptions::IllegalPluginDefinition: [DEPRECATION] Plugin at /Users/redacted/.chef/ohai/cookbo...o be updated to the v7 Ohai plugin format. See https://docs.chef.io/ohai_custom.html for v7 syntax.> with backtrace:
         # ./spec/unit/recipes/default_spec.rb:15:in `block (3 levels) in <top (required)>'
         # ./spec/unit/recipes/default_spec.rb:19:in `block (4 levels) in <top (required)>'
         # ./spec/unit/recipes/default_spec.rb:19:in `block (3 levels) in <top (required)>'
     # ./spec/unit/recipes/default_spec.rb:19:in `block (3 levels) in <top (required)>'

[second test showed same trace]

Finished in 4.48 seconds (files took 2.44 seconds to load)
2 examples, 2 failures

Failed examples:

rspec ./spec/unit/recipes/default_spec.rb:18 # reduction::default When all attributes are default, on Ubuntu 16.04 converges successfully
rspec ./spec/unit/recipes/default_spec.rb:31 # reduction::default When all attributes are default, on CentOS 7.4.1708 converges successfully

ohai

$ ohai -d ~/.chef/ohai/cookbook_plugins
[2018-12-25T07:43:14-05:00] INFO: The plugin path /etc/chef/ohai/plugins does not exist. Skipping...
Traceback (most recent call last):
	12: from /usr/local/bin/ohai:296:in `<main>'
	11: from /usr/local/bin/ohai:296:in `load'
	10: from /opt/chefdk/embedded/lib/ruby/gems/2.5.0/gems/ohai-14.8.10/bin/ohai:26:in `<top (required)>'
	 9: from /opt/chefdk/embedded/lib/ruby/gems/2.5.0/gems/ohai-14.8.10/lib/ohai/application.rb:80:in `run'
	 8: from /opt/chefdk/embedded/lib/ruby/2.5.0/benchmark.rb:293:in `measure'
	 7: from /opt/chefdk/embedded/lib/ruby/gems/2.5.0/gems/ohai-14.8.10/lib/ohai/application.rb:82:in `block in run'
	 6: from /opt/chefdk/embedded/lib/ruby/gems/2.5.0/gems/ohai-14.8.10/lib/ohai/application.rb:111:in `run_application'
	 5: from /opt/chefdk/embedded/lib/ruby/gems/2.5.0/gems/ohai-14.8.10/lib/ohai/system.rb:93:in `all_plugins'
	 4: from /opt/chefdk/embedded/lib/ruby/gems/2.5.0/gems/ohai-14.8.10/lib/ohai/system.rb:100:in `load_plugins'
	 3: from /opt/chefdk/embedded/lib/ruby/gems/2.5.0/gems/ohai-14.8.10/lib/ohai/loader.rb:78:in `load_all'
	 2: from /opt/chefdk/embedded/lib/ruby/gems/2.5.0/gems/ohai-14.8.10/lib/ohai/loader.rb:78:in `each'
	 1: from /opt/chefdk/embedded/lib/ruby/gems/2.5.0/gems/ohai-14.8.10/lib/ohai/loader.rb:79:in `block in load_all'
/opt/chefdk/embedded/lib/ruby/gems/2.5.0/gems/ohai-14.8.10/lib/ohai/loader.rb:133:in `load_plugin_class': [DEPRECATION] Plugin at /Users/redacted/.chef/ohai/cookbook_plugins/ohai/plugin_helpers.rb is a version 6 plugin. Version 6 plugins are no longer supported by Ohai. This plugin will need to be updated to the v7 Ohai plugin format. See https://docs.chef.io/ohai_custom.html for v7 syntax. (Ohai::Exceptions::IllegalPluginDefinition)

This cookbook is currently broken in 5.0.1

Version 5.0.1 will not compile and will not deploy. If you view the build, the approved commit broke the release.

================================================================================
Recipe Compile Error in /tmp/kitchen/cache/cookbooks/ohai/resources/hint.rb
================================================================================

   NoMethodError
   -------------
   undefined method `class_eval' for nil:NilClass

   Cookbook Trace:
   ---------------
     /tmp/kitchen/cache/cookbooks/ohai/resources/hint.rb:5:in `class_from_file'

   Relevant File Content:
   ----------------------
   /tmp/kitchen/cache/cookbooks/ohai/resources/hint.rb:

     1:  property :hint_name, kind_of: String, name_attribute: true
     2:  property :content, kind_of: Hash
     3:  property :compile_time, [true, false], default: true
     4:
     5>> action_class.class_eval do
     6:    def ohai_hint_path
     7:      path = ::File.join(::Ohai::Config[:hints_path].first, new_resource.hint_name)
     8:      path << '.json' unless path.end_with?('.json')
     9:      path
    10:    end
    11:
    12:    def build_content
    13:      # passing nil to file produces deprecation warnings so pass an empty string
    14:      return nil if new_resource.content.nil? || new_resource.content.empty?

   Platform:
   ---------
   x86_64-linux

Ohai and plugin paths with subdirectories has validation issues

Cookbook version

5.2.2

Chef-client version

13.9.1

Platform Details

RHEL 7

Scenario:

Custom plugins

Steps to Reproduce:

To use subdirectories in your ohai plugins directory you cannot do the intuitive:

# Plugin dir is '/etc/chef/ohai_plugins'
ohai_plugin 'filesystem2' do
  source_file 'plugins/bsd/filesystem2.rb'
  plugin_path '/etc/chef/ohai_plugins/bsd'
end

Because you will get warnings that /etc/chef/ohai_plugins/bsd isn't in your plugin path (but if course it is, if /etc/chef/ohai_plugins is then all subdirectories are too.

Now you CAN make this work with:

ohai_plugin 'bsd/filesystem2' do
  source_file 'plugins/bsd/filesystem2.rb'
  plugin_path '/etc/chef/ohai_plugins'
end

But this seems less-good. and more repetitive. At the very least the validation https://github.com/chef-cookbooks/ohai/blob/master/libraries/plugin_helpers.rb#L50 should probably be:

::Ohai::Config.ohai['plugin_path'].map { |x| normalize_path(x) }.any? do |d|
  desired_dir.start_with?(d)
end

But I suspect that's not the only change that would be required.

Expected Result:

The first one to work

Actual Result:

The first one yells at you and causes reloads of Ohai on every run.

Unneeded reloading…

https://github.com/opscode-cookbooks/ohai/blob/master/recipes/default.rb#L23-L26 is not included by default and forces reloads on every converge.

debug code:

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'])

  Chef::Log.error("node path: #{node['ohai']['plugin_path']}")
  Chef::Log.error("config path: #{Ohai::Config[:plugin_path]}")

  Ohai::Config[:plugin_path] = [node['ohai']['plugin_path'], Ohai::Config[:plugin_path]].flatten.compact


  Chef::Log.error "reload_ohai 1: #{reload_ohai}"

  reload_ohai ||= true
end
Chef::Log.info("ohai plugins will be at: #{node['ohai']['plugin_path']}")
Chef::Log.error "reload_ohai 2: #{reload_ohai}"

output:

      [2015-06-15T01:07:25+00:00] ERROR: node path: /etc/chef/ohai_plugins
       [2015-06-15T01:07:25+00:00] ERROR: config path: ["/opt/chef/embedded/lib/ruby/gems/2.1.0/gems/ohai-8.3.0/lib/ohai/plugins"]
       [2015-06-15T01:07:25+00:00] ERROR: reload_ohai 1: false
       [2015-06-15T01:07:25+00:00] ERROR: reload_ohai 2: true

As seen with the nginx and sysctl cookbooks from supermarket.

related: sous-chefs/nginx#344

  • Chef 12.3.0-1, test-kitchen with vagrant & chef-zero
  • Ubuntu 12.04
  • Ohai: 8.3.0

Example .kitchen.yml

driver:
  name: vagrant

provisioner:
  name: chef_zero

platforms:
  - name: ubuntu-12.04
    run_list:
        - recipe[apt]

suites:
  - name: default
    run_list:
      - recipe[nginx::default]

NameError: No resource, method, or local variable named desired_plugin_path

Cookbook version

5.0.0

Chef-client version

12.5.3

Platform Details

centos7

Scenario:

configure a custom plugin using cookbook file and custom ohai_plugins path

Steps to Reproduce:

use ohai_plugin resource on a company cookbook with your plugin file as a cookbook file

ohai_plugin "Physicalmem" do
  name "pmemory"
  path node['ohai']['plugin_path']
  source_file 'plugins/ohai_memmory.rb'
end

Plugin code:

Ohai.plugin(:PhysicalMemory) do
  provides 'memory/physical'

  collect_data(:linux) do
    memory Mash.new unless memory

    begin
      so = shell_out('dmidecode -t memory')
      size_in_mb = so.stdout.lines.grep(/^\tSize: ([0-9]*)/).map(&:split)[0].collect(&:to_i).map(&:to_i).reduce(&:+)
      size = "#{size_in_mb * 1024}kB"
    rescue
      size = '0kB'
    end
    memory['physical'] = size
  end
end

Expected Result:

Plugin on /etc/chef/ohai_plugins and working

Actual Result:

ohai_plugin[Physicalmem] (stic_base::_ohai_memory line 32) had an error: NameError: No resource, method, or local variable named desired_plugin_path' for LWRP resource ohai_plugin from cookbook ohai action provider "Physicalmem"'

The function is defined on /tmp/kitchen/cache/cookbooks/ohai/resources/plugin.rb:12 but chef-client complains about not being defined.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.