2017-01-02 100 views
-1

我是紅寶石和廚師的新手。我試圖通過模板資源創建一個文件。運行chef-apply命令後,出現「NoMethodError:未定義方法`preferred_filename_on_disk_location'爲nil:NilClass」的錯誤。我試圖谷歌它,但沒有找到正確的解決方案。NoMethodError:未定義方法`preferred_filename_on_disk_location'爲零:NilClass

請幫忙。

廚師申請abc.rb

配方:(廚師申請食譜)::(廚師申請配方) *模板[file.txt的]操作創建

================================================================================ 
Error executing action `create` on resource 'template[file.txt]' 
================================================================================ 

NoMethodError 
------------- 
undefined method `preferred_filename_on_disk_location' for nil:NilClass 

Resource Declaration: 
--------------------- 
# In abc.rb 

10: template "file.txt" do 
11:  source "file.erb" 
12:  mode "0666" 
13: end 
14: 

Compiled Resource: 

#在聲明abc.rb:10:在`run_chef_recipe」

template("file.txt") do 
    action [:create] 
    retries 0 
    retry_delay 2 
    default_guard_interpreter :default 
    source "file.erb" 
    declared_type :template 
    cookbook_name "(chef-apply cookbook)" 
    recipe_name "(chef-apply recipe)" 
    mode "0666" 
    path "file.txt" 
end 

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

[2017-01-02T18:37:07-05:00]致命:堆棧跟蹤轉儲到/var/chef/cache/chef-stacktrace.out [2017-01-02T18:37:07-0 5:00]致命錯誤:如果提交錯誤報告 [2017-01-02T18:37:07-05:00],請提供stacktrace.out文件的內容致命錯誤:NoMethodError:template [file.txt](( (主廚申請食譜)第10行)有一個錯誤:NoMethodError:未定義方法`preferred_filename_on_disk_location'爲零:NilClass

+0

歡迎來到StackOverflow。請嘗試修復您問題的格式 - 如果您的代碼和錯誤消息格式正確,將會更容易地爲您提供幫助。 –

+0

請看[ask]和[mcve] –

回答

0

看起來好像chef-apply無法正確運行模板資源(請參閱https://tickets.opscode.com/browse/CHEF-5317)。作爲運行食譜的更好方法,您應該使用chef-solo

該命令將是

chef-solo -o 'recipe[COOKBOOK_NAME]' -c CONFIG_FILE 

其中CONFIG_FILE包含廚師,例如一些配置

current_dir = File.dirname(__FILE__) 

file_cache_path '/tmp/chef-cache' 
cookbook_path ["#{current_dir}/cookbooks"] 
data_bag_path "#{current_dir}/databags" 
ssl_verify_mode :verify_none 

可以調用這個文件solo.rb,把它在你運行上面的廚師命令相同的目錄,那麼它看起來像

chef-solo -o 'recipe[COOKBOOK_NAME]' -c solo.rb 

你想要的菜譜的名稱替換COOKBOOK_NAME如果要運行recipe_name.rb配方而不是default.rb配方,請添加::recipe_name

+1

可能值得添加一個鏈接到https://learn.chef.io,因爲OP似乎缺乏廚師的基本知識。如果你只知道廚師申請(只針對本地主機的快速配置),那麼從單一配方與廚師應用到食譜和廚師零或獨奏並不那麼容易 – Tensibai

+0

我解決了這個問題,使用廚師獨奏這對當前版本是正確的。 – coderanger

相關問題