首页 > 解决方案 > Chef-client 没有名为“source”的资源或方法

问题描述

尝试配置新服务器时出现以下错误。以前一切都很好,所以不知道为什么我会得到这个。这是我在使用模板时不能再使用源吗?

NoMethodError
-------------
No resource or method named `source' for `Chef::Recipe "default"'

Cookbook Trace:
---------------
  /var/chef/cache/cookbooks/switch/recipes/default.rb:15:in `from_file'

Relevant File Content:
----------------------
/var/chef/cache/cookbooks/switch/recipes/default.rb:


 13:  if node.chef_environment == 'uk'
 14:    template "/etc/odbc.ini"
 15>>   source "odbc.ini.erb"
 16:    mode 0644
 17:  end
 18:
 19:  case node['switch']['install_method']
 20:  when 'package'
 21:    include_recipe 'switch::package'
 22:  when 'source'
 23:    include_recipe 'switch::source'
 24:  end

System Info:
------------
chef_version=12.21.31
platform=debian
platform_version=8.10
ruby=ruby 2.3.5p376 (2017-09-14 revision 59905) [x86_64-linux]
program_name=chef-client worker: ppid=2913;start=14:31:46;
executable=/opt/chef/bin/chef-client`

标签: chef-infra

解决方案


您的代码似乎是错误的,试试这个:

if node.chef_environment == 'uk'
  template "/etc/odbc.ini" do
    source "odbc.ini.erb"
    mode 0644
  end
end

您的模板资源丢失了doend因此 Chef 试图自己调用source它。您可以在此处查看资源语法:

资源是具有四个组件的 Ruby 块:类型、名称、一个(或多个)属性(带有值)和一个(或多个)操作。资源的语法如下:

type 'name' do
   attribute 'value'
   action :type_of_action
end

推荐阅读