I am trying to create an LWRP that will call the resource that is defined within itself. My cookbook's structure is as follows:
In the machine cookbook's provider, I have a code snippet as follows:
require 'chef/provisioning' # driver for creating machines
require '::File'
def get_environment_json
@@environment_template = JSON.parse(File::read(new_resource.template_path + "environment.json"))
return @@environment_template
end
The code is only trying to read a json file and I am using File::read for it.
I keep getting an error as follows:
cannot load such file -- ::File
Does anyone know how I can use File::read inside my LWRP's provider?
OK, so the prior two answers are both half right. You have two problems.
First, you can't require ::File
as it's already part of Ruby. This is the cause of your error.
Second, if you call File.read
you will grab Chef's File
not ruby's. You need to do a ::File.read
to use Ruby's File class.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With