【问题标题】:Chef does non sequential recipe executionChef 执行非顺序配方执行
【发布时间】:2013-11-05 21:12:24
【问题描述】:

我遵循教程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

我使用 chef-solo。我的主机已过时 apt repo 信息。 旧的 apt repo 应该不是问题,因为我的运行列表中的第一个配方 更新它。但是厨师忽略了apt recipe,从mysql one开始。

查看日志

dan@mywp3:~/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 之前,但没有任何成功。

我可以通过在 chef-solo 之前在 bash 脚本中手动放置 apt-get update 来解决此问题。

mysql 食谱有这么差吗?据我所知,厨师总是遵循运行列表海峡前进。

【问题讨论】:

  • 您是否检查过此文件是否存在:/var/lib/apt/periodic/update-success-stamp?如果此文件存在,则不会执行命令apt-get update
  • apt-get 只是一个例子。我尝试了自己的手工食谱,只是打印了 hello world,结果相同。

标签: ruby gem chef-infra cookbook


【解决方案1】:

一般来说 chef 将始终遵守运行列表。但是,有时您可能希望在任何其他资源之前运行资源(例如配置包管理器,apt/yum/等)。 mysql ruby​​ 配方中似乎发生的事情是该配方在编译时显式运行一些包安装(在厨师开始执行资源之前)。他们失败了,因为 apt 配方还没有运行(没有)。

有一篇很好的操作码帖子解释了编译/执行阶段here

mysql::ruby 中有问题的代码是

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

run_action(:install) 告诉厨师现在(在编译时)运行它。

【讨论】:

  • 我有一个 wiki 文章的链接,该文章介绍了 Chef 食谱的编译和执行阶段之间的差异的文档,但现在它是 404'ing。如果我得到一个有效的网址,我会尝试发布它......
  • 该死的事情:如果没有 jsessionid 参数,链接将无法工作...(直接取自谷歌搜索结果)wiki.opscode.com/display/chef/…
  • 该链接已经在帖子中,请换行以使其更加明显。不过,谢谢。
  • 指向 wiki.opscode.com 的链接现已失效。 This blog对Chef执行的两个阶段有合理的解释。
【解决方案2】:

我在裸 ubuntu 12.04(没有任何手动预更新)上获得了没有失败的 phpap 配方,并进行了以下修复。

我从 phpap 一中删除了食谱“build-essential”和“openssl”。 更改后,厨师按预期执行食谱。

但奇怪的行为无法解释。

【讨论】:

    【解决方案3】:
    vagrant destroy -f && vagrant up // destroy everything and start over => OK
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-02-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多