2013-10-26 17 views
5

我也跟着教程http://gettingstartedwithchef.com/,第1章廚師是不連續的處方執行

我運行列表是

"run_list": [ "recipe[apt]", "recipe[phpap]" ] 

我phpap食譜我的食譜

include_recipe "apache2" 
include_recipe "build-essential" 
include_recipe "openssl" 
include_recipe "mysql::client" 
include_recipe "mysql::server" 
include_recipe "php" 
include_recipe "php::module_mysql" 
include_recipe "apache2::mod_php5"  
include_recipe "mysql::ruby" 

依賴的默認食譜

depends "apache2" 
depends "mysql" 
depends "php" 
depends "database" 

我的回購有以下下載的食譜

apache2 aws    database openssl phpap xml 
apt  build-essential   mysql php  postgresql xfs 

我使用廚師獨奏。我的主機已經過時了回購信息。 舊的apt回購應該不成問題,因爲我的運行列表 中的第一個處方更新它。但廚師忽略適當的配方,並從MySQL開始。

請參閱日誌

[email protected]:~/chef-repo$ sudo chef-solo -c solo.rb -j web.json 
Starting Chef Client, version 11.6.2 
Compiling Cookbooks... 
[2013-10-27T00:59:28+04:00] WARN: Cloning resource attributes for service[apache2] from prior resource (CHEF-3694) 
[2013-10-27T00:59:28+04:00] WARN: Previous service[apache2]: /home/dan/chef-repo/cookbooks/apache2/recipes/default.rb:24:in `from_file' 
[2013-10-27T00:59:28+04:00] WARN: Current service[apache2]: /home/dan/chef-repo/cookbooks/apache2/recipes/default.rb:210:in `from_file' 
[2013-10-27T00:59:28+04:00] WARN: Cloning resource attributes for directory[/var/cache/local/preseeding] from prior resource (CHEF-3694) 
[2013-10-27T00:59:28+04:00] WARN: Previous directory[/var/cache/local/preseeding]: /home/dan/chef-repo/cookbooks/apt/recipes/default.rb:76:in `block in from_file' 
[2013-10-27T00:59:28+04:00] WARN: Current directory[/var/cache/local/preseeding]: /home/dan/chef-repo/cookbooks/mysql/recipes/server.rb:44:in `from_file' 
[2013-10-27T00:59:28+04:00] WARN: Cloning resource attributes for directory[/var/lib/mysql] from prior resource (CHEF-3694) 
[2013-10-27T00:59:28+04:00] WARN: Previous directory[/var/lib/mysql]: /home/dan/chef-repo/cookbooks/mysql/recipes/server.rb:117:in `block in from_file' 
[2013-10-27T00:59:28+04:00] WARN: Current directory[/var/lib/mysql]: /home/dan/chef-repo/cookbooks/mysql/recipes/server.rb:117:in `block in from_file' 
[2013-10-27T00:59:28+04:00] WARN: Cloning resource attributes for template[/etc/mysql/my.cnf] from prior resource (CHEF-3694) 
[2013-10-27T00:59:28+04:00] WARN: Previous template[/etc/mysql/my.cnf]: /home/dan/chef-repo/cookbooks/mysql/recipes/server.rb:134:in `from_file' 
[2013-10-27T00:59:28+04:00] WARN: Current template[/etc/mysql/my.cnf]: /home/dan/chef-repo/cookbooks/mysql/recipes/server.rb:194:in `from_file' 
Recipe: mysql::client 
    * package[mysql-client] action install 
================================================================================ 
Error executing action `install` on resource 'package[mysql-client]' 
================================================================================ 


Chef::Exceptions::Exec 
---------------------- 
apt-get -q -y install mysql-client=5.5.32-0ubuntu0.12.04.1 returned 100, expected 0 


Cookbook Trace: 
--------------- 
/home/dan/chef-repo/cookbooks/mysql/recipes/ruby.rb:44:in `block in from_file' 
/home/dan/chef-repo/cookbooks/mysql/recipes/ruby.rb:43:in `each' 
/home/dan/chef-repo/cookbooks/mysql/recipes/ruby.rb:43:in `from_file' 
/home/dan/chef-repo/cookbooks/phpap/recipes/default.rb:20:in `from_file' 


Resource Declaration: 
--------------------- 
# In /home/dan/chef-repo/cookbooks/mysql/recipes/client.rb 

46: package name 
47: end 



Compiled Resource: 
------------------ 
# Declared in /home/dan/chef-repo/cookbooks/mysql/recipes/client.rb:46:in `block in from_file' 

package("mysql-client") do 
    action :install 
    retries 0 
    retry_delay 2 
    package_name "mysql-client" 
    version "5.5.32-0ubuntu0.12.04.1" 
    cookbook_name :mysql 
    recipe_name "client" 
end 




================================================================================ 
Recipe Compile Error in /home/dan/chef-repo/cookbooks/phpap/recipes/default.rb 
================================================================================ 


Chef::Exceptions::Exec 
---------------------- 
package[mysql-client] (mysql::client line 46) had an error: Chef::Exceptions::Exec: apt-get -q -y install mysql-client=5.5.32-0ubuntu0.12.04.1 returned 100, expected 0 


Cookbook Trace: 
--------------- 
    /home/dan/chef-repo/cookbooks/mysql/recipes/ruby.rb:44:in `block in from_file' 
    /home/dan/chef-repo/cookbooks/mysql/recipes/ruby.rb:43:in `each' 
    /home/dan/chef-repo/cookbooks/mysql/recipes/ruby.rb:43:in `from_file' 
    /home/dan/chef-repo/cookbooks/phpap/recipes/default.rb:20:in `from_file' 


Relevant File Content: 
---------------------- 
/home/dan/chef-repo/cookbooks/mysql/recipes/ruby.rb: 

37: when 'rhel' 
38:  resources('yum_key[RPM-GPG-KEY-percona]').run_action(:add) 
39:  resources('yum_repository[percona]').run_action(:add) 
40: end 
41: end 
42: 
43: node['mysql']['client']['packages'].each do |name| 
44>> resources("package[#{name}]").run_action(:install) 
45: end 
46: 
47: chef_gem 'mysql' 
48: 


[2013-10-27T00:59:30+04:00] ERROR: Running exception handlers 
[2013-10-27T00:59:30+04:00] ERROR: Exception handlers complete 
[2013-10-27T00:59:30+04:00] FATAL: Stacktrace dumped to /home/dan/chef-solo/chef-stacktrace.out 
Chef Client failed. 0 resources updated 
[2013-10-27T00:59:30+04:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1) 

主機上運行的Ubuntu 12.04。 我試圖把我自己的食譜在運行列表中的phpap之前,但沒有任何成功。

我可以解決這個問題,手動將apt-get更新放在bash腳本中,然後在廚師獨奏之前。

難道它是mysql的食譜嗎?據我所知,廚師ALWAYS一直沿着奔跑列表前進。

+0

你檢查過這個文件是否存在:'/ var/lib/apt/periodic/update-success-stamp'?如果此文件存在,則不會執行命令「apt-get update」。 – shawnzhu

+0

apt-get只是一個例子。我嘗試了自己的手工製作食譜,只是用相同的結果打印出你好。 –

回答

1

在裸ubuntu 12.04(沒有任何手動預更新)和下面的修復中,我得到了phpap配方沒有失敗。

我從phpap中刪除了「build-essential」和「openssl」的配方。 之後改變廚師如預期執行食譜。

但奇怪的行爲,原因不明。

7

總的來說廚師將永遠的榮譽運行名單。但是有時候你可能想在其他任何人之前運行一個資源(比如配置一個軟件包管理器,apt/yum/etc)。在Ruby ruby​​配方中似乎發生了什麼是配方在編譯時顯式運行了一些軟件包安裝(在廚師開始執行資源之前)。由於適當的配方還沒有運行(沒有),它們失敗了。

有一個很好的opscode後解釋編譯/執行階段here

在MySQL中,有問題的代碼::紅寶石

node['mysql']['client']['packages'].each do |name| 
    resources("package[#{name}]").run_action(:install) 
end 

run_action(:install)告訴廚師立即運行這個(在編譯時)。

+0

我有一篇關於廚師食譜的編譯和執行階段之間的差異文檔的wiki文章的鏈接,但現在是404'。我會嘗試發佈它,如果我得到一個工作的網址... –

+0

最難的事情:鏈接不工作沒有jsessionid參數...(直接從谷歌搜索結果)https://wiki.opscode。 com/display/chef/Evaluate + and + Run + Resources + at +編譯+時間; jsessionid = BBE750D0DC249823649B3F4F70F24C82 –

+0

該鏈接已在帖子中,請換行換行以使其更明顯。謝謝,不過。 –

0
vagrant destroy -f && vagrant up // destroy everything and start over => OK