我正嘗試使用廚師獨奏使虛擬機擁有特定的主機名。看起來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'
謝謝!我認爲你幾乎肯定是對的。我從http://www.opinionatedprogrammer.com/2011/06/chef-solo-tutorial-managing-a-single-server-with-chef/學習,它提到了一個配方(我認爲),但不提供元數據。 RB。你是否有一個鏈接到一個具有良好的metadata.rb的回購協議,以幫助指出我的文件與我的配方的關係,以及有效的metadata.rb文件必須採用什麼樣的結構? – Ninjaxor
嘗試從https://learn.chef.io/重新開始,這是我們的實際教程。在未來,儘量不要使用2011年以來的教育材料;-) – coderanger
我並不是故意粗魯,但我不認爲你知道有多少人因廚師官方文檔的不足而被剝奪了公民權。這是一個不同的經驗,從你的同事那裏學習廚師,也看看碼頭或主要從碼頭學習。你甚至不知道在你自己的文檔中特定的位置來解決這個問題是一個非常明顯的指標,說明廚師出了什麼問題。 Thx的投票,很好的觸摸...... – Ninjaxor