2016-08-22 37 views
-1

我正嘗試使用廚師獨奏使虛擬機擁有特定的主機名。看起來chef有一個功能可以包含你自己的其他人的食譜,其中包含複雜的邏輯來解釋edgecase場景,例如從平臺上刪除hostname.sh。嘗試使用廚師獨奏來應用我的食譜時,出現以下錯誤。在Ubuntu 14.04上找不到cookbook的資源

NameError 
--------- 
Cannot find a resource for cookbook on ubuntu version 14.04 


Cookbook Trace: 
--------------- 
    /home/vagrant/chef/cookbooks/op/recipes/default.rb:17:in `from_file' 


Relevant File Content: 
---------------------- 
/home/vagrant/chef/cookbooks/op/recipes/default.rb: 

10: # username is pretty fragile... 
11: username = File.basename(Dir['/home/*'].first) 
12: 
13: file '/etc/motd' do 
14: content "#{hostname}\n\nThis server does: \n-Dokku" 
15: end 
16: 
17>> cookbook 'hostname', '~> 0.4.0' 
18: 
19: default_attributes :set_fqdn => '*.project-domain.com' 
20: 

這裏有幾招我想配置的完整內容: (廚師/食譜/ OP /食譜/ default.rb)

# --- Install packages we need --- 
package 'ntp' 
package 'sysstat' 
package 'git' 

# --- Set host name --- 
# Note how this is plain Ruby code, so we can define variables to 
# DRY up our code: 
hostname = 'epd-dokku.local' 
# username is pretty fragile... 
username = File.basename(Dir['/home/*'].first) 

file '/etc/motd' do 
    content "#{hostname}\n\nThis server does: \n-Dokku" 
end 

cookbook 'hostname', '~> 0.4.0' 

default_attributes :set_fqdn => '*.project-domain.com' 

# file '/etc/hostname' do 
# content "#{hostname}\n" 
# end 
# 
# service 'hostname.sh' do 
# action :restart 
# end 

file '/etc/hosts' do 
    content "127.0.0.1 localhost #{hostname}\n" 
end 


######################### 
# Put dotfiles in place # 
######################### 

git "#{ENV['HOME']}/dotfiles" do 
    repository "https://github.com/my_gh_name/dotfiles.git" 
    action :checkout 
end 

# you still need to run ./make.sh as the actual non-root user acct though... 
execute "#{ENV['HOME']}/dotfiles/make.sh" do 
    # user username 
    cwd "#{ENV['HOME']}/dotfiles" 
end 

["#{ENV['HOME']}/.this_machine", "/home/#{username}/.this_machine"].each do |this_machine_path| 
    file this_machine_path do 
    content "bash_display_style=server" 
    end 
end 

我有一個懷疑,代碼使用主機名所需的必須與我目前所擁有的不同。

cookbook 'hostname', '~> 0.4.0' 

default_attributes :set_fqdn => '*.project-domain.com' 

回答

1

有關指定相關性和包括配方的文檔可以在配方文檔中找到。

「管理基本Web應用程序」教程(https://learn.chef.io/manage-a-web-app/ubuntu/)包括一個步驟,您可以指定對其他食譜的依賴關係,並在自己的食譜中使用該食譜中的食譜。查看該教程的第三部分,「確保apt cache是​​最新的。」

我創建了一個簡單的食譜,其中包括主機名菜譜,並使用其默認的配方在我自己的食譜 - https://github.com/nathenharvey/my_hostname

-Nathen

0

cookbook 'hostname', '~> 0.4.0'線屬於你的metadata.rb,而不是在一個配方。同樣,default_attributes是你在角色中設置的東西,而不是配方。我認爲你試圖混合和匹配來自不同上下文的API。

+0

謝謝!我認爲你幾乎肯定是對的。我從http://www.opinionatedprogrammer.com/2011/06/chef-solo-tutorial-managing-a-single-server-with-chef/學習,它提到了一個配方(我認爲),但不提供元數據。 RB。你是否有一個鏈接到一個具有良好的metadata.rb的回購協議,以幫助指出我的文件與我的配方的關係,以及有效的metadata.rb文件必須採用什麼樣的結構? – Ninjaxor

+0

嘗試從https://learn.chef.io/重新開始,這是我們的實際教程。在未來,儘量不要使用2011年以來的教育材料;-) – coderanger

+0

我並不是故意粗魯,但我不認爲你知道有多少人因廚師官方文檔的不足而被剝奪了公民權。這是一個不同的經驗,從你的同事那裏學習廚師,也看看碼頭或主要從碼頭學習。你甚至不知道在你自己的文檔中特定的位置來解決這個問題是一個非常明顯的指標,說明廚師出了什麼問題。 Thx的投票,很好的觸摸...... – Ninjaxor