【问题标题】:Error installing Postgres Gem using Chef使用 Chef 安装 Postgres Gem 时出错
【发布时间】:2016-04-28 05:16:08
【问题描述】:

我正在使用 Chef Solo 构建 Vagrant 配置(用于 Nginx、PHP 和 Postgres),在配置期间使用 databox 食谱在 Postgresql 中创建数据库。我不断收到以下错误,我追踪到databox::postgresql 最终调用(通过database::paostgresql)调用postgresql::ruby 配方。我尝试直接在我的运行列表中运行postgresql::ruby,它会产生相同的错误。

登录到 VM 并运行 sudo /opt/ruby/bin/gem install pg 可以正常工作,并且重新运行 vagrant provision 也可以正常工作。但是,据我了解,postgresql::ruby 任务的全部意义在于它安装了这个 gem!

这是运行 仅此配方的 Chef 运行的输出(为便于阅读,稍作编辑):

Running chef-solo...
[2014-07-23T19:33:52+00:00] INFO: Forking chef instance to converge...
[2014-07-23T19:33:52+00:00] INFO: *** Chef 11.12.8 ***
[2014-07-23T19:33:52+00:00] INFO: Chef-client pid: 1627
[2014-07-23T19:33:53+00:00] INFO: Setting the run_list to ["postgresql::ruby"] from CLI options
[2014-07-23T19:33:53+00:00] INFO: Run List is [recipe[postgresql::ruby]]
[2014-07-23T19:33:53+00:00] INFO: Run List expands to [postgresql::ruby]
[2014-07-23T19:33:53+00:00] INFO: Starting Chef Run for vm
[2014-07-23T19:33:53+00:00] INFO: Running start handlers
[2014-07-23T19:33:53+00:00] INFO: Start handlers complete.
[2014-07-23T19:33:57+00:00] INFO: execute[apt-get update] ran successfully
[2014-07-23T19:34:09+00:00] INFO: package[ncurses-dev] is a virtual package, actually acting on package[libncurses5-dev]

================================================================================
Error executing action `install` on resource 'chef_gem[pg]'
================================================================================


LoadError
---------
cannot load such file -- pg


Cookbook Trace:
---------------
/tmp/vagrant-chef-3/chef-solo-1/cookbooks/postgresql/recipes/ruby.rb:25:in `from_file'



Resource Declaration:
---------------------
# In /tmp/vagrant-chef-3/chef-solo-1/cookbooks/postgresql/recipes/ruby.rb

 58:     chef_gem "pg"
 59:   rescue Gem::Installer::ExtensionBuildError => e



Compiled Resource:
------------------
# Declared in /tmp/vagrant-chef-3/chef-solo-1/cookbooks/postgresql/recipes/ruby.rb:58:in `rescue in from_file'

chef_gem("pg") do
  provider Chef::Provider::Package::Rubygems
  action :install
  retries 0
  retry_delay 2
  guard_interpreter :default
  package_name "pg"
  version "0.17.1"
  cookbook_name :postgresql
  recipe_name "ruby"
end


================================================================================
Recipe Compile Error in /tmp/vagrant-chef-3/chef-solo-1/cookbooks/postgresql/recipes/ruby.rb
================================================================================

LoadError
---------
chef_gem[pg] (postgresql::ruby line 58) had an error: LoadError: cannot load such file -- pg


Cookbook Trace:
---------------
  /tmp/vagrant-chef-3/chef-solo-1/cookbooks/postgresql/recipes/ruby.rb:25:in `from_file'


Relevant File Content:
----------------------
/tmp/vagrant-chef-3/chef-solo-1/cookbooks/postgresql/recipes/ruby.rb:

 18:  # limitations under the License.
 19:  #
 20:
 21:  # Load the pgdgrepo_rpm_info method from libraries/default.rb
 22:  ::Chef::Recipe.send(:include, Opscode::PostgresqlHelpers)
 23:
 24:  begin
 25>>   require 'pg'
 26:  rescue LoadError
 27:
 28:    if platform_family?('ubuntu', 'debian')
 29:      e = execute 'apt-get update' do
 30:        action :nothing
 31:      end
 32:      e.run_action(:run) unless ::File.exists?('/var/lib/apt/periodic/update-success-stamp')
 33:    end
 34:


[2014-07-23T19:34:29+00:00] ERROR: Running exception handlers
[2014-07-23T19:34:29+00:00] ERROR: Exception handlers complete
[2014-07-23T19:34:29+00:00] FATAL: Stacktrace dumped to /var/chef/cache/chef-stacktrace.out
[2014-07-23T19:34:29+00:00] ERROR: chef_gem[pg] (postgresql::ruby line 58) had an error: LoadError: cannot load such file -- pg
[2014-07-23T19:34:29+00:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)

Chef never successfully completed! Any errors should be visible in the
output above. Please fix your recipes so that they properly complete.

在这次失败的运行中,我没有做任何不寻常的事情 - 虚拟机是使用 Packer 构建的库存 Vagrant Ubuntu 14.04 x64 映像 - Packer 对映像所做的唯一事情就是安装 Chef 和 VirtualBox 扩展。

知道这里发生了什么吗?我没有看到其他人抱怨这个 - 我做错了什么还是没有其他人使用这个食谱?

Chef 是 11.12.8 版本。

完整的MCVE可以找到here


我也在postgresql cookbook 本身上发布了这个问题,但我认为它可能会在这里获得更多曝光。

【问题讨论】:

  • 你读过关于ruby 食谱的重要说明吗?您是否将其包含在您的run_list 中? github.com/hw-cookbooks/postgresql#ruby
  • @sethvargo 是的,我读过它,但那里链接的问题并没有描述我遇到的问题。它描述了一个不同的错误。至于run_list,我已经在问题中指出,当我包含postgresql::ruby 或包含它的任何其他配方时会发生这种情况。

标签: postgresql chef-infra chef-solo


【解决方案1】:

据我所知,似乎只有在将 Chef 作为 gem 安装时才会发生此问题。

我从使用 Chef Gem 切换到使用 Omnibus,并且能够使其正常工作。

【讨论】:

    猜你喜欢
    • 2016-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-14
    • 2015-12-27
    • 2014-01-16
    • 2013-03-09
    相关资源
    最近更新 更多