2012-07-08 92 views
26

厨师似乎在以一种奇怪的顺序处理资源,导致我的构建失败。我的主制程(mytardis-chef/site-cookbooks/recipes/default.rb)开始是这样的:厨师:为什么跳过“include_recipe”步骤中的资源?

include_recipe "build-essential" 
include_recipe "mytardis::deps" 
include_recipe "mytardis::nginx" 
include_recipe "mytardis::postgresql" 

mytardis-chef/cookbooks/build-essential/recipes/default.rb看起来是这样的:

case node['platform'] 
when "ubuntu","debian" 
    %w{build-essential binutils-doc}.each do |pkg| 
    package pkg do 
     action :install 
    end 
    end 
when "centos","redhat","fedora","scientific" 
    %w{gcc gcc-c++ kernel-devel make}.each do |pkg| 
    package pkg do 
     action :install 
    end 
    end 
end 

...(这是一个旧版本的https://github.com/opscode-cookbooks/build-essential/blob/master/recipes/default.rb

在运行时,其原因我不明白,这个建设必不可少的配方得到加载,但没有执行:

[default] Waiting for VM to boot. This can take a few minutes. 
[default] VM booted and ready for use! 
[default] Mounting shared folders... 
[default] -- v-root: /vagrant 
[default] -- v-csr-3: /tmp/vagrant-chef-1/chef-solo-3/roles 
[default] -- v-csc-2: /tmp/vagrant-chef-1/chef-solo-2/cookbooks 
[default] -- v-csc-1: /tmp/vagrant-chef-1/chef-solo-1/cookbooks 
[default] -- v-csdb-4: /tmp/vagrant-chef-1/chef-solo-4/data_bags 
[default] Running provisioner: Vagrant::Provisioners::ChefSolo... 
[default] Generating chef JSON and uploading... 
[default] Running chef-solo... 
[Sun, 08 Jul 2012 05:14:32 +0200] INFO: *** Chef 10.12.0 *** 
[Sun, 08 Jul 2012 05:14:32 +0200] DEBUG: Building node object for lucid32 
[Sun, 08 Jul 2012 05:14:32 +0200] DEBUG: Extracting run list from JSON attributes provided on command line 
[Sun, 08 Jul 2012 05:14:32 +0200] INFO: Setting the run_list to ["recipe[mytardis]"] from JSON 
[Sun, 08 Jul 2012 05:14:32 +0200] DEBUG: Applying attributes from json file 
[Sun, 08 Jul 2012 05:14:32 +0200] DEBUG: Platform is ubuntu version 10.04 
[Sun, 08 Jul 2012 05:14:32 +0200] INFO: Run List is [recipe[mytardis]] 
[Sun, 08 Jul 2012 05:14:32 +0200] INFO: Run List expands to [mytardis] 
[Sun, 08 Jul 2012 05:14:32 +0200] INFO: Starting Chef Run for lucid32 
[Sun, 08 Jul 2012 05:14:32 +0200] INFO: Running start handlers 
[Sun, 08 Jul 2012 05:14:32 +0200] INFO: Start handlers complete. 
... 
[Sun, 08 Jul 2012 05:14:33 +0200] DEBUG: Loading Recipe mytardis via include_recipe 
[Sun, 08 Jul 2012 05:14:33 +0200] DEBUG: Found recipe default in cookbook mytardis 
[Sun, 08 Jul 2012 05:14:33 +0200] DEBUG: Loading Recipe build-essential via include_recipe 
[Sun, 08 Jul 2012 05:14:33 +0200] DEBUG: Found recipe default in cookbook build-essential 
[Sun, 08 Jul 2012 05:14:33 +0200] DEBUG: Loading Recipe mytardis::deps via include_recipe 
[Sun, 08 Jul 2012 05:14:33 +0200] DEBUG: Found recipe deps in cookbook mytardis 
[Sun, 08 Jul 2012 05:14:33 +0200] DEBUG: Loading Recipe mytardis::nginx via include_recipe 
[Sun, 08 Jul 2012 05:14:33 +0200] DEBUG: Found recipe nginx in cookbook mytardis 
[Sun, 08 Jul 2012 05:14:33 +0200] DEBUG: Loading Recipe iptables via include_recipe 
[Sun, 08 Jul 2012 05:14:33 +0200] DEBUG: Found recipe default in cookbook iptables 
[Sun, 08 Jul 2012 05:14:33 +0200] DEBUG: Loading Recipe mytardis::postgresql via include_recipe 
[Sun, 08 Jul 2012 05:14:33 +0200] DEBUG: Found recipe postgresql in cookbook mytardis 
[Sun, 08 Jul 2012 05:14:33 +0200] DEBUG: Loading Recipe postgresql::server via include_recipe 
[Sun, 08 Jul 2012 05:14:33 +0200] DEBUG: Found recipe server in cookbook postgresql 
[Sun, 08 Jul 2012 05:14:33 +0200] DEBUG: Loading Recipe postgresql::client via include_recipe 
[Sun, 08 Jul 2012 05:14:33 +0200] DEBUG: Found recipe client in cookbook postgresql 
[Sun, 08 Jul 2012 05:14:33 +0200] INFO: Processing package[postgresql-client] action install (postgresql::client line 37) 
[Sun, 08 Jul 2012 05:14:33 +0200] DEBUG: package[postgresql-client] checking package status for postgresql-client 
.... 
[Sun, 08 Jul 2012 05:14:45 +0200] ERROR: gem_package[pg] (postgresql::client line 42) has had an error 
. 
make 
sh: make: not found 

也就是说,构建必要的配方是“找到”和“加载”,但它是postgres配方首先得到“处理”。由于build-essential(安装C编译器)没有运行,后者失败。

我Vagrantfile的相关部分看起来是这样的:

config.vm.provision :chef_solo do |chef| 
    chef.log_level = :debug 
    chef.cookbooks_path = ["mytardis-chef/site-cookbooks", "mytardis-chef/cookbooks"] 
    chef.roles_path = "mytardis-chef/roles" 
    chef.data_bags_path = "mytardis-chef/data_bags" 
    chef.add_recipe "mytardis"  
    end 

我以前使用的厨师(?也许10.10.0)的稍早版本在该版本中,建立必要的也没有运行,但是mytardis :: deps是。现在使用Chef 10.12.0。物理机器是OSX,VM是Ubuntu Lucid。

所以,有几个问题:

  1. 为什么是建立必要的没有被 “处理”?
  2. 什么是正确的方法来做到这一点? (我没有写这些食谱,我知道他们确实或已经为他们的作者工作过。)
  3. 网站食谱和烹饪书的“阴影”功能是否仍然有效?它被认为不推荐使用:http://tickets.opscode.com/browse/CHEF-2308(我尝试在网站cookbooks/mytardis/recipes/build-essential下做一个符号链接,但没有喜悦)。
+0

您可以在build-essential/recipes/default.rb中放入Chef :: Log.info(“我在#{cookbook_name} ::#{recipe_name}”),并且它会在加载食谱。由异常处理程序创建的文件(如“/var/chef/cache/failed-run-data.json”)也将拥有其加载的所有资源的全部资源集合,这可以帮助调试资源是否在配方添加。 – jtimberman 2012-07-08 16:26:18

+0

食谱阴影特征是,您可以通过将烹饪书中的组件放在现场烹饪书中,而不是在两个位置单独使用烹饪书,从而覆盖烹饪书中存在的组件。 – jtimberman 2012-07-08 16:27:04

+0

你能解决这个问题吗? – 2012-08-27 22:54:13

回答

40

事实证明,这是厨师是如何工作的一个非常正常的(但下记录的)一部分:它编译的一切,并运行然后开始。除了一些食谱(如Postgres的)插队实际上在编译时安装,使用这样的代码:

action :nothing 
end.run_action(:run) 

的解决方案是,任何需要运行的Postgres之前还需要做到这一点。幸运的是,更新版本的Build-essentials允许这样做。

name "myapp" 
run_list(
    "recipe[build-essential]", 
    "recipe[myapp]" 
) 
default_attributes(
    "build_essential" => { 
    "compiletime" => true 
    } 
) 
+1

考虑将此标记为答案。 – 2012-09-28 10:45:17

+1

今天我遇到了另一个依赖'database :: postgresql'的烹饪书,而这又取决于'postgresql :: ruby​​'。当前的'postgresql :: ruby​​'配方在Chef run的** Compilation **阶段安装'pg' gem,'libpq'和'postgresql'。它通过使用'run_action(:install)'来做到这一点,因为这个答案指出了。 – TrinitronX 2014-03-13 05:43:47

+0

在某些情况下还有另一种解决此问题的方法...例如:在包含'postgresql :: ruby​​'的食谱上运行'厨房测试'可能导致过时的包缓存发生apt错误。为了解决这个问题,我们可以使用'now' cookbook的DSL在厨师开始时强制执行'apt-get update',就像这样:'include_recipe_now'apt'' – TrinitronX 2014-03-13 05:46:54

6

如果写一本菜谱,属性添加到您的属性文件:

node.default['build_essential']['compiletime'] = true 

由于科林你上面设置如下一个角色的属性。

+0

这是特定于build_essential配方,还是做在哪里工作?有记录吗? – 2013-05-06 04:59:51

+0

史蒂夫,该语法可用于任何配方。节点是厨师节点的“自我”引用,默认值是在食谱/食谱使用中应用的自我标题设置,除非再次被覆盖。其他两个选项是build_essential特定的。 – toobulkeh 2013-06-08 03:05:18