Chef environment variables - unset


#1

Dear recipe builders,

I know I can set ephemeral environment variables via ENV['foo']='bar' but how do I “unset” an environment variable I’ve previously set, in Ruby/Chef?

I know I can use the bash command unset to wipe the value for an existing env variable, but I was wondering if this indeed will be active throughout the remainder of the chef-client execution.

I know I can also probably do ENV['foo']='' but just checking if there is a more elegant way possibly.

Regards
Aravind


#2

You can use the delete method.

http://ruby-doc.org/core-2.3.0/ENV.html


#3

Thank you. I am beginning to realize that one needs to have a working knowledge of Ruby to excel with Chef.

Interestingly, from the same Ruby Doc URL you provided:

ENV[name] = value
Sets the environment variable name to value. If the value given is nil the environment variable is deleted. name must be a string.