we set a Chef runlist for a node composed by, let's say, recipe A and then recipe B. In recipe A we execute a command resource that launch a script.sh, which export the $PATH variable on the target machine with a custom path.
Next, when recipe B is executed, it looks for an executable to be launched and we want that it can execute it looking into the paths contained into $PATH. Unfortunately the $PATH variable during recipe B loses the modifies made during recipe A.
The context is: on a machine we have a JVM in a specific path (that is NOT in $PATH). With recipe A we launch a script.sh that export the JVM bin path into $PATH. Then in recipe B we use a java executable (let's say, jar) and so we want that it is executing looking into the path we exported before in $PATH. But it doesn't work.
We want that the JVM path is set temporarily into $PATH just to let recipe B execute. I suppose we cannot use any of Chef environment variable to achieve that, since in a distributed scenario the JVM path can vary from machine to machine.
Thanks a lot.
UPDATE:
Recipe A
mydir = "/path/to/jvm"
script_name = "script.sh"
sh = File.join(mydir,script_name).gsub("/","\/")
script_str = ". " + sh
# Launch script.sh in order to export Java to PATH
execute "ExecuteScript" do
command script_str
user "myuser"
group "mygroup"
only_if {File.exists?(File.join(mydir,script_name))}
end
Unfortunately I cannot publish Recipe B, but keep in mind that it is not editable and it simply execute "java" or "jar" (looking for them in $PATH).
UPDATE 2
I solved this issue setting in recipe A the following:
javapath = "/path/to/jvm/bin"
ENV['PATH'] = "#{ENV['PATH']}:" + javapath
In that way I set the environment variable $PATH for the duration of the Ruby execution. This makes recipe B able to see that variable, and so executing the required bin (jar in my case). I don't know if that is an elegant solution, but it worked for me.