Chef

Chef – 通知多個包

  • January 2, 2016

我正在嘗試在 CentOS 7 上部署 postgresql 9.4

package ['postgresql94-server', 'postgresql94-contrib'] do
   action :nothing
end

execute "yum check-update" do
   command "yum check-update"
   action :nothing
end

package 'Install Postgres Repo' do
   package_name 'pgdg-redhat94'
   source '/tmp/pgdg-redhat94-9.4-2.noarch.rpm'
   notifies :run, 'execute[yum check-update]', :immediately
   notifies :install, 'package[postgresql94-server, postgresql94-contrib]', :immediately
   action :nothing
end

execute 'Download Postgres repo RPM' do
   command 'curl http://yum.postgresql.org/9.4/redhat/rhel-7-x86_64/pgdg-redhat94-9.4-2.noarch.rpm -o /tmp/pgdg-redhat94-9.4-2.noarch.rpm'
   notifies :install, 'package[Install Postgres Repo]', :immediately
end

我收到以下錯誤:

[root@db01 ~]# chef-client 
Starting Chef Client, version 12.6.0
resolving cookbooks for run list: ["postgres94"]
Synchronizing Cookbooks:
 - postgres94 (0.1.0)
Compiling Cookbooks...
Converging 4 resources

Running handlers:
[2015-12-30T15:32:16+00:00] ERROR: Running exception handlers
Running handlers complete
[2015-12-30T15:32:16+00:00] ERROR: Exception handlers complete
Chef Client failed. 0 resources updated in 01 seconds
[2015-12-30T15:32:16+00:00] FATAL: Stacktrace dumped to /var/chef/cache/chef-stacktrace.out
[2015-12-30T15:32:16+00:00] FATAL: Please provide the contents of the stacktrace.out file if you file a bug report
[2015-12-30T15:32:16+00:00] ERROR: resource yum_package[Install Postgres Repo] is configured to notify resource package[postgresql94-server, postgresql94-contrib] with action install, but package[postgresql94-server, postgresql94-contrib] cannot be found in the resource collection. yum_package[Install Postgres Repo] is defined in /var/chef/cache/cookbooks/postgres94/recipes/default.rb:19:in `from_file'

[2015-12-30T15:32:16+00:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)
[root@db01 ~]# chef-client 
Starting Chef Client, version 12.6.0
resolving cookbooks for run list: ["postgres94"]
Synchronizing Cookbooks:
 - postgres94 (0.1.0)
Compiling Cookbooks...
Converging 4 resources

Running handlers:
[2015-12-30T15:32:30+00:00] ERROR: Running exception handlers
Running handlers complete
[2015-12-30T15:32:30+00:00] ERROR: Exception handlers complete
Chef Client failed. 0 resources updated in 01 seconds
[2015-12-30T15:32:30+00:00] FATAL: Stacktrace dumped to /var/chef/cache/chef-stacktrace.out
[2015-12-30T15:32:30+00:00] FATAL: Please provide the contents of the stacktrace.out file if you file a bug report
[2015-12-30T15:32:30+00:00] ERROR: resource yum_package[Install Postgres Repo] is configured to notify resource package[postgresql94-server, postgresql94-contrib] with action install, but package[postgresql94-server, postgresql94-contrib] cannot be found in the resource collection. yum_package[Install Postgres Repo] is defined in /var/chef/cache/cookbooks/postgres94/recipes/default.rb:19:in `from_file'

[2015-12-30T15:32:30+00:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)

我究竟做錯了什麼?

雖然該錯誤報告中正在解決此問題,但這裡有一個解決方法:

p = package ['postgresql94-server', 'postgresql94-contrib'] do
   action :nothing
end
# ...
notifies :install, p, :immediately

您始終可以為通知傳遞顯式資源對象。

引用自:https://serverfault.com/questions/745990