Error when installing a new gem 'concurrent-ruby'

Hi I am trying to install a new gem using chef_gem. I checked and found it installed but I still keep getting the same error.

================================================================================
Recipe Compile Error in /var/chef/cache/cookbooks/clari_base/libraries/get_authorized_user_keys.rb
================================================================================
LoadError
---------
cannot load such file -- concurrent
Cookbook Trace:
---------------
  /var/chef/cache/cookbooks/.....3:in `<top (required)>'
Relevant File Content:
----------------------
/var/chef/cache/cookbooks/<path_to_file>:
  1:  require 'chef/recipe'
  2:  require 'aws-sdk'
  3>> require 'concurrent'
  4:  require 'set'
  5:
  6:  # someComment
  7:  module someMethod
  8:
  9:    BUCKET = "<Bucket_Name>"
 10:    MAX_KEYS = 1000
 11:
Platform:
---------
x86_64-linux

Can someone please help? Thanks!

The code you're sharing shows only the require, it doesn't install or whatever, mind sharing the code where the gem is installed ?

Hi Tensibai,

Thank you for replying. Here's the code:

# Install the concurrent-ruby gem
chef_gem 'concurrent-ruby' do
  compile_time false
  action :nothing
end.run_action(:install)

That's super bizarre to set compile_time to false to then make it run at compile time with the old trick od end.run_action(:install).

This should work the same:

# Install the concurrent-ruby gem
chef_gem 'concurrent-ruby' do
  compile_time true
  action :install
end

Now if your require is present before this chef_gem resource, Chef didn't had a chance to install it before requiring it.

Are you trying to require it in a library ? you obfuscated so much of the path that it's hard to tell.

If so you should move to metadata gem entry instead. metadata.rb

Thanks again for replying. Let me try that and let you know. And yes, I'm trying to require it in a library. Does it mean the lib files will be compiled first? I'm new to chef, so just trying stuff out and I'm stuck with this for the last couple of weeks.

Also, I'm not sure I understand, did you mean that I should move the chef_gem to metadata.rb? Please let me know. Thanks again!

So yes, chef run has a bit of complex phases when running, they are described here Chef Infra Client Overview but the fact cookbooks files in the libraries directory are evaluated before attributes or recipes is hard to find.

The metadata gem keyword has been implemented exactly for that, so you can require gems in your own libraries. The caveat is that it can only install 'normal' gems (I.e: those not needing compilation)

This is actually a small project for my work. I would like it to be installed on all the chef clients. So if I add it to metadata.rb, will it still get installed everywhere? Thanks!