Chef infra chef运行其资源的顺序是什么?

Chef infra chef运行其资源的顺序是什么?,chef-infra,chef-recipe,chef-solo,recipe,Chef Infra,Chef Recipe,Chef Solo,Recipe,我和厨师有一次意想不到的经历。这是: 我宣布了安装postgres的方法 execute 'sudo apt-get install postgresql-9.1 -y --force-yes' template "/etc/postgres/9.1/main/pg_hba.conf" do source "pg_hba.conf.erb" owner "postgres" group "postgres" mode 00600 notifies :restart, 'se

我和厨师有一次意想不到的经历。这是:

我宣布了安装postgres的方法

execute 'sudo apt-get install postgresql-9.1 -y --force-yes'

template "/etc/postgres/9.1/main/pg_hba.conf" do
  source "pg_hba.conf.erb"
  owner "postgres"
  group "postgres"
  mode 00600
  notifies :restart, 'service[postgresql]', :immediately
  subcribes:
end

service "postgresql" do
  service_name "postgresql"
  supports :restart => true, :status => true, :reload => true
  action [:enable, :start]
end
但当我和测试厨房跑的时候

Compiling Cookbooks...
       Recipe: beesor-cookbook::postgresql
  * execute[sudo apt-get install postgresql-9.1 -y --force-yes] action run       [2014-03-14T17:37:28+00:00] INFO: Processing execute[sudo apt-get install postgresql-9.1 -y --force-yes] action run (beesor-cookbook::postgresql line 4)
Reading package lists...       
Building dependency tree...       
Reading state information...       
       postgresql-9.1 is already the newest version.
       0 upgraded, 0 newly installed, 0 to remove and 31 not upgraded.
       [2014-03-14T17:37:29+00:00] INFO: execute[sudo apt-get install postgresql-9.1 -y --force-yes] ran successfully

           - execute sudo apt-get install postgresql-9.1 -y --force-yes

Converging 3 resources       
  * execute[sudo apt-get install postgresql-9.1 -y --force-yes] action nothing[2014-03-14T17:37:29+00:00] INFO: Processing execute[sudo apt-get install postgresql-9.1 -y --force-yes] action nothing (beesor-cookbook::postgresql line 4)       
 (skipped due to action :nothing)       
  * template[/etc/postgres/9.1/main/pg_hba.conf] action create[2014-03-14T17:37:29+00:00] INFO: Processing template[/etc/postgres/9.1/main/pg_hba.conf] action create (beesor-cookbook::postgresql line 8)       

           * Parent directory /etc/postgres/9.1/main does not exist.

       ================================================================================
       Error executing action `create` on resource 'template[/etc/postgres/9.1/main/pg_hba.conf]'
       ================================================================================

       Chef::Exceptions::EnclosingDirectoryDoesNotExist
       ------------------------------------------------
       Parent directory /etc/postgres/9.1/main does not exist.

       Resource Declaration:
       ---------------------
       # In /tmp/kitchen/cookbooks/beesor-cookbook/recipes/postgresql.rb

         8: template "/etc/postgres/9.1/main/pg_hba.conf" do
         9:   source "pg_hba.conf.erb"
        10:   owner "postgres"
        11:   group "postgres"
        12:   mode 00600
        13:   notifies :restart, 'service[postgresql]', :immediately
        14: end
        15: 

       Compiled Resource:
       ------------------
       # Declared in /tmp/kitchen/cookbooks/beesor-cookbook/recipes/postgresql.rb:8:in `from_file'

       template("/etc/postgres/9.1/main/pg_hba.conf") do
         provider Chef::Provider::Template
         action "create"
         retries 0
         retry_delay 2
         path "/etc/postgres/9.1/main/pg_hba.conf"
         backup 5
         atomic_update true
         source "pg_hba.conf.erb"
         cookbook_name :"beesor-cookbook"
         recipe_name "postgresql"
         owner "postgres"
         group "postgres"
         mode 384
       end       

       [2014-03-14T17:37:29+00:00] INFO: Running queued delayed notifications before re-raising exception
       [2014-03-14T17:37:29+00:00] ERROR: Running exception handlers
       [2014-03-14T17:37:29+00:00] ERROR: Exception handlers complete
       [2014-03-14T17:37:29+00:00] FATAL: Stacktrace dumped to /tmp/kitchen/cache/chef-stacktrace.out
       Chef Client failed. 1 resources updated
       [2014-03-14T17:37:29+00:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)
Converge failed on instance <postgresql-ubuntu-1204>.
Please see .kitchen/logs/postgresql-ubuntu-1204.log for more details
 ------Exception-------
Class: Kitchen::ActionFailed
Message: SSH exited (1) for command: [sudo -E chef-solo --config /tmp/kitchen/solo.rb --json-attributes /tmp/kitchen/dna.json  --log_level info]
编译食谱。。。
食谱:beesor食谱::postgresql
*执行[sudo apt get install postgresql-9.1-y--force yes]操作运行[2014-03-14T17:37:28+00:00]信息:处理执行[sudo apt get install postgresql-9.1-y--force yes]操作运行(beesor cookbook::postgresql第4行)
正在阅读软件包列表。。。
正在构建依赖关系树。。。
正在读取状态信息。。。
postgresql-9.1已经是最新版本。
0已升级,0已新安装,0已删除,31未升级。
[2014-03-14T17:37:29+00:00]信息:执行[sudo apt get install postgresql-9.1-y--force yes]成功运行
-执行sudo apt get install postgresql-9.1-y——强制是
汇聚3种资源
*执行[sudo apt get install postgresql-9.1-y--force yes]无操作[2014-03-14T17:37:29+00:00]信息:处理执行[sudo apt get install postgresql-9.1-y--force yes]无操作(beesor cookbook::postgresql第4行)
(由于操作而跳过:无)
*模板[/etc/postgres/9.1/main/pg_hba.conf]操作创建[2014-03-14T17:37:29+00:00]信息:处理模板[/etc/postgres/9.1/main/pg_hba.conf]操作创建(beesor cookbook::postgresql第8行)
*父目录/etc/postgres/9.1/main不存在。
================================================================================
执行操作“在资源上创建”模板[/etc/postgres/9.1/main/pg_hba.conf]时出错
================================================================================
Chef::Exceptions::EnclosingDirectoryDoesNotExist
------------------------------------------------
父目录/etc/postgres/9.1/main不存在。
资源声明:
---------------------
#在/tmp/kitchen/cookbook/beesor cookbook/recipes/postgresql.rb中
8:模板“/etc/postgres/9.1/main/pg_hba.conf”do
9:来源“pg_hba.conf.erb”
10:所有者“博士后”
11:“博士后”组
12:00600模式
13:通知:重新启动“服务[postgresql],:立即
14:完
15: 
汇编资源:
------------------
#在/tmp/kitchen/cookbooks/beesor cookbook/recipes/postgresql.rb:8:in‘from_file’中声明
模板(“/etc/postgres/9.1/main/pg_hba.conf”)是否
提供者厨师::提供者::模板
“创建”操作
重试0次
重试\u延迟2
路径“/etc/postgres/9.1/main/pg_hba.conf”
备份5
原子更新为真
来源“pg_hba.conf.erb”
菜谱名称:“比索菜谱”
配方名称“postgresql”
“博士后”所有者
“博士后”组
模式384
结束
[2014-03-14T17:37:29+00:00]信息:在重新引发异常之前运行排队的延迟通知
[2014-03-14T17:37:29+00:00]错误:正在运行异常处理程序
[2014-03-14T17:37:29+00:00]错误:异常处理程序已完成
[2014-03-14T17:37:29+00:00]致命:Stacktrace转储到/tmp/kitchen/cache/chef-Stacktrace.out
Chef客户端失败。1资源更新
[2014-03-14T17:37:29+00:00]致命:Chef::异常::ChildConverge错误:Chef运行进程退出失败(退出代码1)
Converge在实例上失败。
有关更多详细信息,请参见.kitchen/logs/postgresql-ubuntu-1204.log
------例外情况-------
类:Kitchen::ActionFailed
消息:SSH退出(1)以获取命令:[sudo-E chef solo--config/tmp/kitchen/solo.rb--json attributes/tmp/kitchen/dna.json--log_level info]
我以为厨师在经过食谱中的每一个资源时都在运行资源

但它向我展示了相反的一面

厨师怎么样?这里有几点

首先,粘贴的输出不是顶部的配方代码。它显示了一个在编译过程中使用
action:nothing
声明的资源,建议您执行以下操作:

execute 'sudo apt-get install postgresql-9.1 -y --force-yes' do
  action :nothing
end.run_action(:run)
我相信您在试图解决订购问题时做到了这一点(一开始并没有)

其次,Chef完全按照您的期望进行操作,并按照配方中声明的顺序运行每个资源。如果查看
会聚3个资源
行之后的日志,您将看到它执行
执行
,操作为
,然后是
模板
,最后是
服务

在此之前,您还可以看到,它在编译时运行了
execute
资源,并且没有安装任何软件包,因为“
postgresql-9.1已经是最新版本了”(日志中也有明确说明)

第三点,您的配方可能失败了,因为
postgresql-9.1
包没有创建您希望它创建的目录:“
Parent directory/etc/postgres/9.1/main不存在”

第四,安装软件包的惯用方法是使用:



我的建议是:登录要部署此配方的计算机,确保安装了
postgresql-9.1
程序包(如果没有安装,则安装),确保这是您需要的程序包,然后找出特定操作系统的
pg_hba.conf
文件的位置。然后,修复你的
模板
资源以指向正确的位置。

谢谢@cassianoleal,你的帖子非常有用,我解决了我的错误,再次感谢你。+1谢谢你!!
package "postgresql-9.1" do
  action :install
end