RiotGamesCookbooks / rbenv-cookbook

Installs and configures rbenv
http://community.opscode.com/cookbooks/rbenv
Apache License 2.0
137 stars 109 forks source link

node[:languages][:ruby] is not updated #81

Open chulkilee opened 10 years ago

chulkilee commented 10 years ago

Note: I think it is not a problem of this cookbook - rather, it seems to be Chef/Ohai limitation.

node[:languages][:ruby] is set by ohai ruby plugin at the compile time.

rbenv community cookbook makes easy to install rbenv and new ruby versions.

The problem happens when installing rbenv at first. Since there is no rbenv when chef-client starts, Ohai cannot set node[:languages][:ruby]. When chef-client run installs rbenv (creating /etc/profile.d) and new ruby version, still chef-client does not access to them because chef-client run executed without rbenv init. To allow the current chef-client run to access new ruby from rbenv, the cookbook sets PATH variable in initialize_rbenv ruby_block.

At this moment, gem_package resource can install gems in the new ruby from rbenv because it calls 'gem' by default. ref

However node[:languages][:ruby] is still not set. If any other recipes uses node[:languages][:ruby] (either in recipe or attribute), it will be nil.

This happens when I used bluepill cookbook. When running rbenv and bluepill recipies, it installed bluepill gem under rbenv ruby but failed to run blupill service because the bluepill cookbook uses node information to determine ruby bin_dir. ref

I don't know how to deal with this problem. Reloading ohai does not seem to work because it will not change node attributes compiled in other recipes. fnichol/chef-rbenv introduces another LWRP, but it requires updating all other cookbooks to use the LWRP.


from ruby_block

The ruby_block resource is used to execute Ruby code during a chef-client run. Ruby code in the ruby_block resource is evaluated with other resources during convergence, whereas Ruby code outside of a ruby_block resource is evaluated before other resources, as the recipe is compiled.

shlomoswidler commented 10 years ago

Perhaps reloading ohai will help?

ohai "reload ohai" do
  action :reload
end
chulkilee commented 10 years ago

No, it will not update the old ohai value which is fetched to another cookbook when they are compiled - unless they use ruby_block to fetch ohai values.

sbuzonas commented 9 years ago

I'm seeing a similar issue, but what I see is node[:languages][:ruby] is updated on the run that the the profile.d template is created. If that file is present and no changes necessary there is no notification triggered to the ruby_block[initialize_rbenv] resource. I have a working solution, not at all elegant, perhaps someone can make it more pleasant and or address the issue in the default recipe

ruby_block 'load rbenv' do
  block do
    true
  end
  notifies :create, 'ruby_block[initialize_rbenv]', :immediately
end

ohai 'ruby' do
  subscribes :reload, 'ruby_block[initialize_rbenv]', :immediately
end

Then my recipe that uses bluepill has a ruby_block that subscribes to that ohai resource and updates my bluepill paths.