gpt4 book ai didi

ruby - Chef 执行非顺序配方

转载 作者:数据小太阳 更新时间:2023-10-29 07:13:39 25 4
gpt4 key购买 nike

我遵循了教程 http://gettingstartedwithchef.com/ , 第 1 章。

我的运行 list 是

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

我的 phpap Recipe 默认 Recipe

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"

我的 Recipe 的依赖

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

我的仓库有以下下载的 Recipe

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

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

查看日志

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。我试图将我自己的 Recipe 放在运行列表中的 phpap 之前,但没有成功。

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

mysql cookbook这么烂吗?据我所知, Chef 总是遵循运行列表。

最佳答案

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

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

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

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

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

关于ruby - Chef 执行非顺序配方,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19612066/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com