【问题标题】:wrong number of arguments for custom chef provider/resource/recipes自定义厨师提供者/资源/食谱的参数数量错误
【发布时间】:2015-08-08 04:07:32
【问题描述】:

我正在尝试编写自定义资源和提供程序来配置 splunk 文件。

以下是资源/提供者/配方的代码:

splunk/recipes/default.rb

Chef::Log.info "Creating directory /opt/splunkforwarder/etc/apps/myapps/"
directory "/opt/splunkforwarder/etc/apps/myapps/" do
    action :create
end

splunk_monitor "/opt/splunkforwarder/etc/apps/myapps/apache.conf"  do
  monitoring_path         "/logs/logsw0/access_log"
  source_type             "combined_log"
  whitelist               "access"
  index                   "web"
  ignore_older_than       "15d"
  file_path               "/opt/splunkforwarder/etc/apps/myapps/apache.conf"
  action                  :create
end

splunk/resources/monitor.rb

provides :monitor
actions :create
default_action :create

attribute :name, :kind_of => String, :required => true
attribute :monitoring_path, :kind_of =>  String,  :required => true
attribute source_type, :kind_of => String, :required => true
attribute :whitelist, :kind_of => String , :required => true
attribute :index, :kind_of => String, :required => true
attribute :ignore_older_than, :kind_of => String, :required => true
attr_accessor :name, :monitoring_path , ource_type, :whitelist , :index, :ignore_older_than

splunk/providers/monitor.rb

action :create do
template  new_resource.name  do
    source 'input.conf.erb'
    owner 'root'
    group 'root'
    mode  0644
    variables ( {
            "monitoring_path" => new_resource.monitoring_path,
            "whitelist" => new_resource.whitelist,
            "index" => new_resource.index,
            "source_type" => new_resource.source_type,
            "ignore_older_than" => new_resource.ignore_older_than
           }        )
    end

    new_resource.updated_by_last_action(true)
end

在单独运行 chef 时会抛出给定的错误。厨师独奏版是11.12.8。

错误

========================================================================
Recipe Compile Error in /home/rjain/cookbooks/splunk/recipes/default.rb
============================================================================


ArgumentError
-------------
wrong number of arguments (1 for 0)


Cookbook Trace:
---------------
/home/rjain/cookbooks/splunk/recipes/default.rb:7:in `block in from_file'
/home/rjain/cookbooks/splunk/recipes/default.rb:6:in `from_file'

我试图通过比较apt 提供者/资源在我的代码中解决这个问题,但仍然没有运气。 任何人都可以提出代码中的问题。

提前致谢。

【问题讨论】:

    标签: ruby chef-infra chef-recipe chef-solo


    【解决方案1】:

    您可能在资源中缺少一个冒号:

    attribute source_type, :kind_of => String, :required => true
    

    应改为:

    attribute :source_type, :kind_of => String, :required => true
    

    【讨论】:

    • 感谢 Martin 提供的宝贵意见。我在代码中纠正了这个错误,但没有解决这个问题。我发现在 splunk/resource/monitor.rb 文件中,我将属性定义为导致问题的 attr_accessor。评论这一行后,它得到了整理。
    【解决方案2】:

    我在您的资源中没有看到“file_path”参数,但您的资源调用设置了它。此外,正如 Martin 所说,source_type 应该是 :source_type 并且在你的 attr_accessors 列表中ource_type 应该是 :source_type。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多