【问题标题】:Set environment variables for current chef-client run为当前的 chef-client 运行设置环境变量
【发布时间】:2014-10-12 19:17:28
【问题描述】:

我正在尝试使用 chef 安装 OpenJDK,以及下载 Eclipse 并在 Windows 2008 节点上使用 p2 director 安装一些插件。 OpenJDK 安装,我设置我的环境变量 JAVA_HOME 并将其添加到路径中。 但是,在我关闭并重新打开 PowerShell 之前,此更改不会生效。 chef-client 运行在当前会话中需要这些来运行 eclipse p2 导向器。有什么办法可以让我只运行一次 chef-client 吗?

在我安装 openJDK 的秘诀中,我包括:

env "JAVA_HOME" do
  value 'C:\\Program Files\\Zulu\\zulu-8'
end

env "path" do
  delim ";"
  value '%JAVA_HOME%\\bin'
  action :modify
end

#For Command Prompt
execute "setPathCMD" do
  command "set PATH=#{node['java']['path']}\\bin;%PATH%"
end
#For PowerShell
powershell_script "setPathPS" do
  code <<-EOH
  $env:Path="#{node['java']['path']}\\bin;$env:Path"
  EOH
end

ENV['Path'] += ";C:\\Program Files\\Zulu\\zulu-8\\bin"

在我安装 eclipse 插件的秘诀中:

if not node['eclipse']['plugins'].empty?
  node['eclipse']['plugins'].each do |plugin_group|
    repo, id = plugin_group.first
    execute "eclipse plugin install" do
      command "#{node['eclipse']['unzip_location']}/eclipse/eclipse.exe -application org.eclipse.equinox.p2.director -noSplash -repository #{repo} -installIUs #{id}"
      action :run
    end
  end
end

【问题讨论】:

  • @sethvargo 总的来说不错,但您确定 magic_shell_cookbook 可以在 powershell 环境中工作吗?
  • @sethvargo 看了下代码,在 Windows 上不行
  • 您需要为 Windows 调整代码。我确信食谱的维护者会接受 PR。
  • 我可能是错的,但你不需要在你的 openJDK 配方中设置ENV['JAVA_HOME'] 以便当前(和子)进程知道吗?

标签: windows powershell chef-infra chef-recipe


【解决方案1】:

穿上你的client.rbsolo.rb

ENV['VAR'] = 'value'

【讨论】:

    【解决方案2】:

    尝试使用 setx:

    execute 'set java_home' do
      command "setx -m JAVA_HOME \"C:\\Program Files\\Zulu\\zulu-8\""
      only_if { ENV['JAVA_HOME'] != 'C:\\Program Files\\Zulu\\zulu-8' }
    end
    
    # Set JAVA_HOME for this process
    ENV['JAVA_HOME'] = 'C:\\Program Files\\Zulu\\zulu-8'
    
    # do something similar for path...
    

    改编自用于启用 NuGet 包还原的 visualstudio 食谱: https://github.com/daptiv/visualstudio/blob/master/recipes/nuget.rb

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-06-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-06-25
      • 1970-01-01
      • 2020-04-06
      • 2018-11-28
      相关资源
      最近更新 更多