How can you use a Chef recipe to set an environment variable?
I need to set an environment variable using a Chef recipe. Can you provide an example of how to accomplish this?
How can you use a Chef recipe to set an environment variable?
I need to set an environment variable using a Chef recipe. Can you provide an example of how to accomplish this?
If you want to set it at the system level in
/etc/environment
, you can do so directly per the following example without adding an additional recipe (this adds two env variables for Java):If you want to set it on the system with Chef, checkout the magic_shell cookbook.
If you need an env var set strictly within the Chef process, you can use
ENV['foo'] = 'bar
' since it's a ruby process.If you need to set one for an execute provider, Chef exposes an environment hash:
If you're looking to set a persistent environment variable then you may want to have Chef edit
/etc/profile.d/chef.sh
,/etc/environment
, a users' profile, etc.