bash_profile is not taking effect with chef-run

梦想的初衷 提交于 2019-12-02 07:24:20

There are a few things here:

Your not_if is wrong

not_if { $JAVA_HOME == "#{ENV['JAVA_HOME']}" && $PATH = "#{ENV['PATH']}:#{node['java']['path']}/bin" }

You are confusing Ruby and bash here. IN Ruby $JAVA_HOME refers to a global constant. It's unclear to me what your not_if guard is trying to accomplish, but using it as-is is certainly not correct.

Using bash instead of primitive resources

You are using Bash to echo content into a file. This is a perfect job for the file or template resources. The will be idempotent and handle notifications properly:

file '~/.bash_profile` do
  content <<-EOH
    export JAVA_HOME=$JAVAHOME
    export PATH=$PATH
  EOH
end

However, it is worth noting that the script as you have it does nothing. You are setting the values of JAVA_HOME and PATH to themselves. It is likely that you want to use #{ENV['JAVA_HOME']} instead.

Bash is a subshell resource

When you use the bash (or any execute resource), you are executing in a subshell, so things like source or export are not persisted to the parent process.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!