繁体   English   中英

声明包资源时提供名称-Chef

[英]Supplying a name when declaring a package resource - Chef

我有以下Chef食谱( web.rb ):

# Install Apache and start the service.
httpd_service 'customers' do
  mpm 'prefork'
  action [:create, :start]
end

# Add the site configuration.
httpd_config 'customers' do
  instance 'customers'
  source 'customers.conf.erb'
  notifies :restart, 'httpd_service[customers]'
end

# Create the document root directory.
directory node['awesome_customers_ubuntu']['document_root'] do
  recursive true
end

# Write the home page.
file "#{node['awesome_customers_ubuntu']['document_root']}/index.html" do
  content '<html>This is a placeholder</html>'
  mode '0644'
  owner node['awesome_customers_ubuntu']['user']
  group node['awesome_customers_ubuntu']['group']
end

我的default.rb配方如下所示:

include_recipe 'apt::default'
include_recipe 'awesome_customers_ubuntu::firewall'
include_recipe 'awesome_customers_ubuntu::web_user'
include_recipe 'awesome_customers_ubuntu::web'

attributes/default.rb

default['firewall']['allow_ssh'] = true
default['awesome_customers_ubuntu']['open_ports'] = 80

default['awesome_customers_ubuntu']['user'] = 'web_admin'
default['awesome_customers_ubuntu']['group'] = 'web_admin'
default['awesome_customers_ubuntu']['document_root'] = '/var/www/customers/public_html'

当我执行kitchen converge ,出现以下错误:

Recipe: awesome_customers_ubuntu::web
         * httpd_service_debian_sysvinit[customers] action create[2016-09-13T02:40:18+00:00] WARN: Default value nil is invalid for property version of resource . Possible fixes: 1. Remove 'default: nil' if nil means 'undefined'. 2. Set a valid default value if there is a reasonable one. 3. Allow nil as a valid value of your property (for example, 'property :version, [ String, nil ], default: nil'). Error: Property version must be one of: String!  You passed nil. at /tmp/kitchen/cache/cookbooks/httpd/libraries/helpers.rb:101:in `default_package_name'
       [2016-09-13T02:40:18+00:00] WARN: Default value nil is invalid for property package_name of resource . Possible fixes: 1. Remove 'default: nil' if nil means 'undefined'. 2. Set a valid default value if there is a reasonable one. 3. Allow nil as a valid value of your property (for example, 'property :package_name, [ String, nil ], default: nil'). Error: Property package_name must be one of: String!  You passed nil. at /tmp/kitchen/cache/cookbooks/httpd/libraries/httpd_service_debian.rb:8:in `block in <class:HttpdServiceDebian>'


           ================================================================================
           Error executing action `create` on resource 'httpd_service_debian_sysvinit[customers]'
           ================================================================================

           ArgumentError
           -------------
           You must supply a name when declaring a package resource

           Cookbook Trace:
           ---------------
           /tmp/kitchen/cache/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/dsl/declare_resource.rb:302:in `build_resource'
           /tmp/kitchen/cache/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/dsl/declare_resource.rb:259:in `declare_resource'
           /tmp/kitchen/cache/cookbooks/httpd/libraries/httpd_service_debian.rb:8:in `block in <class:HttpdServiceDebian>'
           /tmp/kitchen/cache/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/provider.rb:132:in `instance_eval'
           /tmp/kitchen/cache/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/provider.rb:132:in `compile_and_converge_action'
           /tmp/kitchen/cache/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/runner.rb:78:in `run_action'
           /tmp/kitchen/cache/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/runner.rb:106:in `block (2 levels) in converge'
           /tmp/kitchen/cache/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/runner.rb:106:in `each'
           /tmp/kitchen/cache/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/runner.rb:106:in `block in converge'
           /tmp/kitchen/cache/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/runner.rb:105:in `converge'

           Resource Declaration:
           ---------------------
           # In /tmp/kitchen/cache/cookbooks/awesome_customers_ubuntu/recipes/web.rb

             8: httpd_service "customers" do
             9:     mpm "prefork"
            10:     action [:create, :start]
            11: end
            12: 

           Compiled Resource:
           ------------------
           # Declared in /tmp/kitchen/cache/cookbooks/awesome_customers_ubuntu/recipes/web.rb:8:in `from_file'

           httpd_service_debian_sysvinit("customers") do
             action [:create, :start]
             retries 0
             retry_delay 2
             default_guard_interpreter :default
             declared_type :httpd_service
             cookbook_name "awesome_customers_ubuntu"
             recipe_name "web"
             mpm "prefork"
           end

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

       Recipe: firewall::default
         * firewall[default] action restart
            (skipped due to only_if)
          (skipped due to only_if)
        (skipped due to only_if)
       * file[/etc/default/ufw-chef.rules] action create (up to date)
        (up to date)

       Running handlers:
       [2016-09-13T02:40:18+00:00] ERROR: Running exception handlers
       Running handlers complete
       [2016-09-13T02:40:18+00:00] ERROR: Exception handlers complete
       Chef Client failed. 3 resources updated in 06 seconds
       [2016-09-13T02:40:18+00:00] FATAL: Stacktrace dumped to /tmp/kitchen/cache/chef-stacktrace.out
       [2016-09-13T02:40:18+00:00] FATAL: Please provide the contents of the stacktrace.out file if you file a bug report
       [2016-09-13T02:40:18+00:00] ERROR: httpd_service_debian_sysvinit[customers] (awesome_customers_ubuntu::web line 8) had an error: ArgumentError: You must supply a name when declaring a package resource
       [2016-09-13T02:40:19+00:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)

我该如何解决这个问题?

似乎在https://github.com/chef-cookbooks/httpd/blob/master/libraries/httpd_service_debian.rb#L8处 ,package_name为nil。

通过线索跟踪这https://github.com/chef-cookbooks/httpd/blob/master/libraries/httpd_service.rb#L23依赖于从延迟加载的包名https://github.com/chef-cookbooks /httpd/blob/master/libraries/info_service_packages.rb#L37

您可以通过明确声明资源为:

httpd_service 'customers' do 
  mpm 'prefork'
  package_name 'apache2'
  action [:create, :start]
end

虽然,您确实不需要! 也许提出一个错误?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM