Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plugin_path configuration issue with custom plugins #54

Open
Annih opened this issue Dec 7, 2016 · 6 comments
Open

Plugin_path configuration issue with custom plugins #54

Annih opened this issue Dec 7, 2016 · 6 comments
Labels
Triage: Needs Information Indicates an issue needs more information in order to work on it. Triage: Support Indicates an issue that is a support question and will be redirected to other mediums.

Comments

@Annih
Copy link

Annih commented Dec 7, 2016

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

@Annih Annih changed the title Plugin_path configuration issue when defining a custom plugin Plugin_path configuration issue with custom plugins Dec 9, 2016
@cheeseplus
Copy link

Pretty sure there isn't anything unexpected here - if the attribute check is moved into the recipe as opposed to the attributes I'm pretty sure you'd get the desired effect. Try that and let us know - at least as I read this there isn't anything wrong so much as the order of operations should simply be changed.

@Annih
Copy link
Author

Annih commented Apr 12, 2017

Thanks for your suggestion, it surely "works", but this is not the described scenario ... I want to use my attribute in the attribute file. I don't want to move it to the recipe, I want the ohai attributes available in attributes phase, which seems to me normal.
For me, attributes files are here to compute attributes at certain time in the process, I don't want to compute my attributes in recipes, otherwise it breaks the flow, and the cookbook depending on me won't be able to rely on my attributes.

To rephrase my question:

I want to have access to custom ohai plugin's attributes inside attributes file; is there any other way than changing the Ohai::plugin_path using the chef-client cookbook?

@iennae
Copy link

iennae commented May 2, 2017

What do you mean by the "attributes phase"? This cookbook isn't going to change how ohai works. The error you are pasting in here is around test kitchen + ohai.

@Annih
Copy link
Author

Annih commented Aug 27, 2017

@iennae the example I give you is a repro in kitchen yes.
When I talkk about attribute phase, I'm trying to name the phase when the attributes are compiled.

I'll try to explain in a different way, let's say cookbook B depends on an ohai attribute defined in cookbook A

  1. ohai runs
  2. A attributes are compiled
  3. B attributes are compiled
    ... other stuffs are done
  4. A recipe is included and compiled
  5. B recipe is included and compiled

In this example, the "attribute phase" starts after 1. and ends before 4.
During this phase, because my ohai plugin is not in the plugin_path, it has not been loaded at step 1.
So in step 3. B attributes won't be able to compute a value based on the ohai plugin

Is it clearer this way?

@mikemol
Copy link

mikemol commented May 2, 2018

@Annih, if I understand the docs, you need to specify depends 'attributename' in ohai plugin you want to be able to consume an attribute within.

@Annih
Copy link
Author

Annih commented May 2, 2018

Thanks @mikemol for your answer, but in my case I'm not in a ohai plugin, I'm using the result of a plugin in attributes files.

@tas50 tas50 added Triage: Support Indicates an issue that is a support question and will be redirected to other mediums. Triage: Needs Information Indicates an issue needs more information in order to work on it. and removed Type: Question labels Jan 30, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Triage: Needs Information Indicates an issue needs more information in order to work on it. Triage: Support Indicates an issue that is a support question and will be redirected to other mediums.
Projects
None yet
Development

No branches or pull requests

5 participants