在某些网络上,我们将为我们的应用程序提供软件/配置,这些网络处于关闭状态,无法访问Internet。此外,我们所有的客户端都有不同的网络,驱动器布局等,因此没有可用于获取安装程序包的中心位置,例如jdk-8u172-windows-x64.exe,可以在Windows上安装Java 8。 / p>
要解决此问题,我想将exe / msi文件放入食谱中并直接引用它们。我以为我找到了一种方法,可以将exe放入菜谱下的assets
文件夹中,然后引用该文件夹中的文件,但这似乎还不够。
jdk_package = 'jdk-8u172-windows-x64.exe'
jdk_identifier = File.basename( jdk_package, File.extname( jdk_package ) )
jdk_package_installer = File.join( Chef::Config[:file_cache_path], 'cookbooks', cookbook_name, 'assets', jdk_package )
java_attr = node['myapp']['java']
jdk_home = java_attr['jdk_home']
jre_home = java_attr['jre_home']
jdk_package_install_log = java_attr['install_log']
jdk_package_options = "/s ADDLOCAL=\"ToolsFeature,SourceFeature,PublicjreFeature\" INSTALLDIR=\"#{jdk_home}\" /INSTALLDIRPUBJRE=\"#{jre_home}\" /L \"#{jdk_package_install_log}\""
jdk_java_executable = File.expand_path( File.join('bin', 'java.exe'), jdk_home )
jre_java_executable = File.expand_path( File.join('bin', 'java.exe'), jre_home )
windows_package jdk_identifier do
source jdk_package_installer
options jdk_package_options
installer_type :custom
action :install
end
不幸的是,当它运行时,出现了一个问题,因为找不到exe文件。
mynode.local * windows_package[jdk-8u172-windows-x64] action install[2018-09-13T18:28:00+01:00] INFO: Processing windows_package[jdk-8u172-windows-x64] action install (oracle_java8::default line 35)
mynode.local
mynode.local * Source for package jdk-8u172-windows-x64 does not exist
mynode.local ================================================================================
mynode.local Error executing action `install` on resource 'windows_package[jdk-8u172-windows-x64]'
mynode.local ================================================================================
mynode.local
mynode.local Chef::Exceptions::Package
mynode.local -------------------------
mynode.local Source for package jdk-8u172-windows-x64 does not exist
mynode.local
mynode.local Resource Declaration:
mynode.local ---------------------
mynode.local # In c:/chef/cache/cookbooks/oracle_java8/recipes/default.rb
mynode.local
mynode.local 35: windows_package jdk_identifier do
mynode.local 36: source jdk_package_installer
mynode.local 37: options jdk_package_options
mynode.local 38: installer_type :custom
mynode.local 39: action :install
mynode.local 40: end
mynode.local
mynode.local Compiled Resource:
mynode.local ------------------
mynode.local # Declared in c:/chef/cache/cookbooks/oracle_java8/recipes/default.rb:35:in `from_file'
mynode.local
mynode.local windows_package("jdk-8u172-windows-x64") do
mynode.local package_name "jdk-8u172-windows-x64"
mynode.local action [:install]
mynode.local default_guard_interpreter :default
mynode.local declared_type :windows_package
mynode.local cookbook_name "oracle_java8"
mynode.local recipe_name "default"
mynode.local source "c:\\chef\\cache\\cookbooks\\oracle_java8\\assets\\jdk-8u172-windows-x64.exe"
mynode.local options "/s ADDLOCAL=\"ToolsFeature,SourceFeature,PublicjreFeature\" INSTALLDIR=\"D:/OT/jdk8\" /INSTALLDIRPUBJRE=\"D:/OT/jre8\" /L \"D:/OT/chef_install-oracle_java8.log\""
mynode.local installer_type :custom
mynode.local end
mynode.local
mynode.local System Info:
mynode.local ------------
mynode.local chef_version=14.4.56
mynode.local platform=windows
mynode.local platform_version=10.0.14393
mynode.local ruby=ruby 2.5.1p57 (2018-03-29 revision 63029) [x64-mingw32]
mynode.local program_name=C:/opscode/chef/bin/chef-client
mynode.local executable=C:/opscode/chef/bin/chef-client
mynode.local
mynode.local [2018-09-13T18:28:00+01:00] INFO: Running queued delayed notifications before re-raising exception
mynode.local
mynode.local Running handlers:
mynode.local [2018-09-13T18:28:00+01:00] ERROR: Running exception handlers
mynode.local Running handlers complete
mynode.local [2018-09-13T18:28:00+01:00] ERROR: Exception handlers complete
mynode.local Chef Client failed. 12 resources updated in 06 seconds
mynode.local [2018-09-13T18:28:00+01:00] INFO: Sending resource update report (run-id: ce69a476-b437-4462-bb18-c50659326e40)
mynode.local [2018-09-13T18:28:00+01:00] FATAL: Stacktrace dumped to c:/chef/cache/chef-stacktrace.out
mynode.local [2018-09-13T18:28:00+01:00] FATAL: Please provide the contents of the stacktrace.out file if you file a bug report
mynode.local [2018-09-13T18:28:00+01:00] FATAL: Chef::Exceptions::Package: windows_package[jdk-8u172-windows-x64] (oracle_java8::default line 35) had an error: Chef::Exceptions::Package: Source for package jdk-8u172-windows-x64 does not exist
ERROR: Failed to execute command on mynode.local return code 1
我认为这与Chef lazy加载文件的方式有关。
有没有一种方法可以迫使Chef加载它,或者有更好的方法将安装程序打包在食谱中?
答案 0 :(得分:0)
好吧,最后一点也不难。我只需要遵守约定即可。
无需创建名为assets
的自定义文件夹,只需使用cookbook/files/default
子文件夹。这是运行命令chef generate file <filename>
时已添加文件的文件夹。
我将可执行文件放入cookbook/files/default
目录中,然后修改了脚本以引用该文件位置。即
jdk_package_installer = File.join( Chef::Config[:file_cache_path], 'cookbooks', cookbook_name, 'files', 'default', jdk_package )
然后直接从节点上的C:\ chef \ cache文件夹中执行。