错误:未初始化的常量#<class:0x00000005f9fe70> :: ApplicationCookbook

时间:2016-06-03 12:40:54

标签: chef cookbook

使用包括compat_resource 12.10.4在内的一系列cookbook运行chef-client作为独立菜单或依赖于另一本菜谱。我最终在chef-client run上发生致命错误,并看到以下stacktrace。

食谱版

12.10.4

Chef-client版本

24年12月10日

平台详情

OS X本地; centos 6.5服务器

Chef client fatal error: 
[2016-06-02T16:22:13-04:00] WARN: Chef::Provider::AptRepository already exists!  Cannot create deprecation class for LWRP provider apt_repository from cookbook apt
[2016-06-02T16:22:13-04:00] WARN: AptRepository already exists!  Deprecation class overwrites Custom resource apt_repository from cookbook apt

================================================================================
Recipe Compile Error in /var/chef/cache/cookbooks/tomcat/resources/default.rb
================================================================================

NameError
---------
uninitialized constant #<Class:0x00000005f9fe70>::ApplicationCookbook

Cookbook Trace:
---------------
  /var/chef/cache/cookbooks/tomcat/resources/default.rb:20:in `class_from_file'
  /var/chef/cache/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/resource/lwrp_base.rb:50:in `build_from_file'

Relevant File Content:
----------------------
/var/chef/cache/cookbooks/tomcat/resources/default.rb:

 13:  #
 14:  # Unless required by applicable law or agreed to in writing, software
 15:  # distributed under the License is distributed on an "AS IS" BASIS,
 16:  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 17:  # See the License for the specific language governing permissions and
 18:  # limitations under the License.
 19:  
 20>> include ApplicationCookbook::ResourceBase
 21:  
 22:  actions :install, :remove, :restart, :start
 23:  
 24:  attr_accessor :service_name, :clustered 
 25:  attr_accessor :http_port, :ajp_port, :ssl_port, :shutdown_port, :host_name, :session_timeout
 26:  attr_accessor :unpack_wars, :auto_deploy, :jvm_opts, :jmx_opts, :webapp_opts, :resources, :env, :roles, :users
 27:  attr_accessor :jmx_access, :jmx_access_file, :jmx_password_file, :jmx_password
 28:  attr_accessor :more_opts, :user, :context_dir, :log_dir, :tmp_dir, :work_dir, :manage_config_file
 29:  attr_accessor :webapp_dir, :base, :pid_file, :use_security_manager, :group, :shutdown_wait

Platform:
---------
x86_64-linux


Running handlers:
[2016-06-02T16:22:14-04:00] ERROR: Running exception handlers
Running handlers complete
[2016-06-02T16:22:14-04:00] ERROR: Exception handlers complete
Chef Client failed. 0 resources updated in 04 seconds
[2016-06-02T16:22:14-04:00] FATAL: Stacktrace dumped to /var/chef/cache/chef-stacktrace.out
[2016-06-02T16:22:14-04:00] FATAL: Please provide the contents of the stacktrace.out file if you file a bug report
[2016-06-02T16:22:14-04:00] ERROR: uninitialized constant #<Class:0x00000005f9fe70>::ApplicationCookbook
[2016-06-02T16:22:14-04:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)

stacktrace中的第一个文件/行(/var/chef/cache/cookbooks/tomcat/resources/default.rb:20)是这样的:

  

包括ApplicationCookbook :: ResourceBase

stacktrace中的第二行(/var/chef/cache/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/resource/lwrp_base.rb:50)是这样的:

# Call the actual build_from_file
super

这是完整的文件:

require 'chef_compat/resource/lwrp_base'
require 'chef/resource/lwrp_base'

module ChefCompat
  module Monkeypatches
    #
    # NOTE: LOTS OF METAPROGRAMMING HERE. NOT FOR FAINT OF HEART.
    #

    # Add an empty module to Class so we can temporarily override it in build_from_file
    module Class
    end
    class<<::Class
      prepend(ChefCompat::Monkeypatches::Class)
    end

    module Chef
      module Resource
        module LWRPBase
          def build_from_file(cookbook_name, filename, run_context)
            # If the cookbook this LWRP is from depends on compat_resource, fix its LWRPs up real good
            if run_context.cookbook_collection[cookbook_name].metadata.dependencies.has_key?('compat_resource')
              # All cookbooks do Class.new(Chef::Resource::LWRPBase). Change Class.new
              # temporarily to translate Chef::Resource::LWRPBase to ChefCompat::Resource
              ChefCompat::Monkeypatches::Class.module_eval do
                def new(*args, &block)
                  # Trick it! Use ChefCompat::Resource instead of Chef::Resource::LWRPBase
                  if args == [ ::Chef::Resource::LWRPBase ]
                    ChefCompat::Monkeypatches::Class.module_eval do
                      remove_method(:new) if method_defined?(:new)
                    end
                    args = [ ChefCompat::Resource::LWRPBase ]
                  end
                  super(*args, &block)
                end
              end

              begin

                # Call the actual build_from_file
                super # **LINE 50 AS MENTIONED IN STACKTRACE**

              ensure
                class<<ChefCompat::Monkeypatches::Class
                  remove_method(:new) if method_defined?(:new)
                end
              end
            else
              # Call the actual build_from_file
              super
            end
          end
        end
        class <<::Chef::Resource::LWRPBase
          prepend(LWRPBase)
        end
      end
    end
  end
end

1 个答案:

答案 0 :(得分:0)

Chef 12不支持application_java cookbook。它需要移植到我在kickstarter中编写的新代码,但我没有时间也没有Java专业知识来知道如何做到最好。