Plugin_path configuration issue with custom plugins
Annih opened this issue · comments
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
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.
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 thechef-client
cookbook?
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.
@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
- ohai runs
- A attributes are compiled
- B attributes are compiled
... other stuffs are done - A recipe is included and compiled
- 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?
@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.
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.