厨师运营其资源的顺序是什么?

时间:2014-03-14 18:12:30

标签: chef 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, '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]

我认为Chef在配方中的每一个都经过了资源。

但它让我反其道远。

厨师怎么样?

1 个答案:

答案 0 :(得分:2)

这里有几点。

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

execute 'sudo apt-get install postgresql-9.1 -y --force-yes' do
  action :nothing
end.run_action(:run)

我相信您在尝试解决订购问题时所做的事情(首先不存在)。

其次,Chef正在按照您的期望完成任务,并按照您在食谱中声明的顺序运行每个资源。如果您在Converging 3 resources行后查看日志,您会看到它executeaction :nothing一起执行,然后是template,最后是service }。

之前您还可以看到,它在编译期间运行了您的execute资源,并且没有安装任何软件包,因为&#34; postgresql-9.1 is already the newest version&#34; (也在日志中明确说明。)

第三点,你的食谱可能失败了,因为postgresql-9.1包没有创建你期望它的目录:&#34; Parent directory /etc/postgres/9.1/main does not exist&#34;。

第四,安装包的惯用厨师方法是使用package resource

package "postgresql-9.1" do
  action :install
end

我的建议:登录您正在部署此配方的计算机,确保已安装postgresql-9.1软件包(如果不是,请安装它),请确保&#39; ; s您需要的包,然后找出pg_hba.conf文件在该特定操作系统中的位置。然后,修复您的template资源以指向正确的位置。