I am trying to read value of an environment variable in attributes file of chef cookbook. Many posts have described that i can use ENV[] of ruby to achieve what i want.
My attributes file looks something like this
default['some_object']['some_attribute'] = ENV['SOME_ENV_VAR']
While running recipe, it seems to result in empty string. Any pointers?
assume that what you describe is the right way to do so (which is not), note that you need to set the environment variable on the node where you execute
chef-client
.chef-client
execution, has several phases:for more information about chef-client about the phase, see chef-client overview.
the evaluation of your environment variable, namely
ENV['SOME_ENV_VAR']
happens on the compilation phase. what you should really do, is to use json attribute:you can always use the environment variables that are set for you to construct a json structure and then feed it to chef-client when you execute it.