修改:Bug in rubygems 2.4.4. (fixed in 2.4.5)
我在使用chef_gem资源安装带有Chef Client v12.2.1附带的嵌入式ruby的宝石时遇到了问题:
Mixlib::ShellOut::ShellCommandFailed
------------------------------------
chef_gem[zabbixapi] (generic_server_win::libzabbix-deps line 6) had an error: Mixlib::ShellOut::ShellCommand Failed: Expected process to exit with [0], but received '1'
---- Begin output of C:/opscode/chef/embedded/bin/gem install c:/chef/cache/zabbixapi-2.2.2.gem -q --no-rdoc --no-ri -v "2.2.2" ----
STDOUT:
STDERR: ERROR: While executing gem ... (Errno::EADDRNOTAVAIL)
The requested address is not valid in its context. - connect(2)
---- End output of C:/opscode/chef/embedded/bin/gem install c:/chef/cache/zabbixapi-2.2.2.gem -q --no-rdoc --no-ri -v "2.2.2" ----
Ran C:/opscode/chef/embedded/bin/gem install c:/chef/cache/zabbixapi-2.2.2.gem -q --no-rdoc --no-ri -v "2.2.2" returned 1
此外:
这是我的厨师食谱:
cookbook_file "#{Chef::Config[:file_cache_path]}/zabbixapi-2.2.2.gem" do
source 'zabbixapi-2.2.2.gem'
end
chef_gem "zabbixapi" do
source "#{Chef::Config[:file_cache_path]}/zabbixapi-2.2.2.gem"
end
答案 0 :(得分:0)
问题在于chef_gem
资源在Chef安装中强制使用嵌入式ruby的方式是特殊的,并且它在收敛之前运行以允许在配方中需要gem。 documentation about it here
要使用与chef一起部署的本地源,您必须确保该文件存在之前,否则gem命令将尝试下载它(并且无法访问Internet时失败)。
要确保在chef_gem
调用之前存在本地文件,您必须确保在编译时使用this trick调用cookbook_file资源
在您的具体情况下,应该这样做:
cookbook_file "#{Chef::Config[:file_cache_path]}/zabbixapi-2.2.2.gem" do
action :nothing
source 'zabbixapi-2.2.2.gem'
end.run_action(:create)
chef_gem "zabbixapi" do
source "#{Chef::Config[:file_cache_path]}/zabbixapi-2.2.2.gem"
end
资源中的任何操作都不是为了避免它被调用两次(一次在编译阶段,一次在收敛阶段,即使后者不会产生任何影响,最好是节省时间不评估它两次)然后调用定义末尾的操作:create
将在编译阶段触发操作,稍后将chef_gem
调用该文件。