Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chef cookbook - reload PATH

I just installed java using chef cookbook and updated PATH environment variable for all users (added new file to /etc/profile.d/).

Is it possible to tell chef to reload PATH variable?

When I do something like this:

execute "java_check" do
  command "java -version"
end

Is says that java could not be found.

It works fine when I log out, log in again and then run chef recipe.

like image 706
Konrad Avatar asked Dec 06 '25 15:12

Konrad


1 Answers

I'm not 100% sure you can update the PATH variable for future chef runs, but you can set it up manually using the environment attribute within the execute stanza. This can also be used on other Resources as well. See: http://docs.opscode.com/chef/resources.html#execute

From the Chef Docs,

environment
A hash of environment variables: {"ENV_VARIABLE"=>"VALUE"}.
(These environment variables must exist for a command to execute successfully.)
Default value: nil.

Run a command which requires an environment variable

execute "slapadd" do
  command "slapadd < /tmp/something.ldif"
  creates "/var/lib/slapd/uid.bdb"
  action :run
  environment ({'HOME' => '/home/myhome'})
end
like image 57
Sergio Avatar answered Dec 08 '25 18:12

Sergio