处理MySQL cookbook时的Chef客户端错误

时间:2018-02-07 13:39:27

标签: mysql ruby chef cookbook

我正在尝试使用chef-client配置新服务器。该进程遇到一个由未初始化的常量'MysqlCookbook:Helpers'引起的NameError。

这是我得到的输出:

0.0.0.0 Compiling Cookbooks...
0.0.0.0
0.0.0.0 ================================================================================
0.0.0.0 Recipe Compile Error in /var/chef/cache/cookbooks/mysql/libraries/provider_mysql_client.rb
0.0.0.0 ================================================================================
0.0.0.0
0.0.0.0 NameError
0.0.0.0 ---------
0.0.0.0 uninitialized constant MysqlCookbook::Helpers
0.0.0.0
0.0.0.0 Cookbook Trace:
0.0.0.0 ---------------
0.0.0.0   /var/chef/cache/cookbooks/mysql/libraries/provider_mysql_client.rb:7:in `<class:MysqlClient>'
0.0.0.0   /var/chef/cache/cookbooks/mysql/libraries/provider_mysql_client.rb:6:in `<class:Provider>'
0.0.0.0   /var/chef/cache/cookbooks/mysql/libraries/provider_mysql_client.rb:5:in `<class:Chef>'
0.0.0.0   /var/chef/cache/cookbooks/mysql/libraries/provider_mysql_client.rb:4:in `<top (required)>'
0.0.0.0
0.0.0.0 Relevant File Content:
0.0.0.0 ----------------------
0.0.0.0 /var/chef/cache/cookbooks/mysql/libraries/provider_mysql_client.rb:
0.0.0.0
0.0.0.0   1:  require 'chef/provider/lwrp_base'
0.0.0.0   2:  require_relative 'helpers'
0.0.0.0   3:
0.0.0.0   4:  class Chef
0.0.0.0   5:    class Provider
0.0.0.0   6:      class MysqlClient < Chef::Provider::LWRPBase
0.0.0.0   7>>       include MysqlCookbook::Helpers
0.0.0.0   8:        provides :mysql_client if defined?(provides)
0.0.0.0   9:
0.0.0.0  10:        use_inline_resources if defined?(use_inline_resources)
0.0.0.0  11:
0.0.0.0  12:        def whyrun_supported?
0.0.0.0  13:          true
0.0.0.0  14:        end
0.0.0.0  15:
0.0.0.0  16:        action :create do
0.0.0.0
0.0.0.0 System Info:
0.0.0.0 ------------
0.0.0.0 chef_version=12.21.31
0.0.0.0 platform=ubuntu
0.0.0.0 platform_version=16.04
0.0.0.0 ruby=ruby 2.3.5p376 (2017-09-14 revision 59905) [x86_64-linux]
0.0.0.0 program_name=chef-client worker: ppid=31986;start=12:48:17;
0.0.0.0 executable=/opt/chef/bin/chef-client
0.0.0.0
0.0.0.0
0.0.0.0 Running handlers:
0.0.0.0 [2018-02-07T12:48:23+00:00] ERROR: Running exception handlers
0.0.0.0 Running handlers complete
0.0.0.0 [2018-02-07T12:48:23+00:00] ERROR: Exception handlers complete
0.0.0.0 Chef Client failed. 0 resources updated in 05 seconds
0.0.0.0 [2018-02-07T12:48:23+00:00] FATAL: Stacktrace dumped to /var/chef/cache/chef-stacktrace.out
0.0.0.0 [2018-02-07T12:48:23+00:00] FATAL: Please provide the contents of the stacktrace.out file if you file a bug report
0.0.0.0 [2018-02-07T12:48:23+00:00] ERROR: uninitialized constant MysqlCookbook::Helpers
0.0.0.0 [2018-02-07T12:48:23+00:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)

我已经看过它似乎正在崩溃的文件(provider_mysql_client.rb),该文件以下面的代码开头:

require 'chef/provider/lwrp_base'
require_relative 'helpers'

class Chef
  class Provider
    class MysqlClient < Chef::Provider::LWRPBase
      include MysqlCookbook::Helpers
      provides :mysql_client if defined?(provides)

我不是Ruby开发人员(我的背景是PHP和JavaScript),但我认为它包括文件helpers.rb,它与上述文件位于同一目录中。

其内容如下所示:

module MysqlCookbook
  module HelpersBase
    require 'shellwords'

    def el6?
      return true if node['platform_family'] == 'rhel' && node['platform_version'].to_i == 6
      false
    end

对我来说,这看起来与上面的include语句不一致,它引用了MysqlCookbook :: Helpers - 这看起来应该被称为MysqlCookbook :: HelpersBase(我再也不是Ruby dev,所以我可能会在这里弄错)

我不确定如何继续前进并让Chef-client运行成功完成。我在烹饪书GitHub上发现了以下问题 - https://github.com/chef-cookbooks/mysql/issues/540这似乎与我的情况相符,但它没有任何回复,所以对我来说并不是特别有用。

感谢任何意见/建议。

1 个答案:

答案 0 :(得分:0)

在cookbook的8.x.x版中,文件provider_mysql_client.rb不再存在。

确保您没有来自以前版本7.x.x的旧版文件。

如果您正在使用Berkshelf,请尝试删除其缓存(〜/ .berkself)。

如果您要将所有内容复制到目标服务器,然后使用主厨零(-z),请同时查看。