在ubuntu 14.04版上找不到cookbook的资源

时间:2016-08-22 22:00:53

标签: chef

我正在尝试使用chef-solo来使VM具有特定的主机名。似乎厨师有一个功能,包括你自己的其他人的食谱,其中包含复杂的逻辑,以解释从平台删除hostname.sh等边缘情况。尝试使用chef-solo来应用我的食谱时,我得到以下错误。

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'

2 个答案:

答案 0 :(得分:1)

Documentation on assigning dependencies and including recipes can be found in the documentation for recipes.

The "Manage a basic web application" tutorial (https://learn.chef.io/manage-a-web-app/ubuntu/) includes a step where you assign a dependency on another cookbook and use a recipe from that cookbook in your own cookbook. Check out part three of that tutorial, "Ensure the apt cache is up to date."

I've created a simple cookbook that includes the hostname cookbook and uses its default recipe in my own cookbook - https://github.com/nathenharvey/my_hostname

-Nathen

答案 1 :(得分:0)

cookbook 'hostname', '~> 0.4.0'行属于您的metadata.rb,不在食谱中。同样地,default_attributes是你在角色中设置的东西,而不是食谱。我认为您正在尝试混合和匹配来自不同环境的API。