我在尝试配置新服务器时遇到以下错误。以前一切都很好,所以不确定我为什么会这样做。这是否在使用模板时我不能再使用源代码?
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`
答案 0 :(得分:3)
您的代码似乎有误,请尝试:
if node.chef_environment == 'uk'
template "/etc/odbc.ini" do
source "odbc.ini.erb"
mode 0644
end
end
您的模板资源缺少do
和end
,因此Chef尝试自行调用source
。您可以查看资源语法here:
资源是一个Ruby块,包含四个组件:类型,名称,一个 (或更多)属性(带有值)和一个(或多个)操作。该 资源的语法是这样的:
type 'name' do attribute 'value' action :type_of_action end