レシピに必要な一連の gem をインストールしようとしていますが、開発ツール (つまり、gcc、gcc-c++、ruby-devel。詳細についてはこちらを参照) を本番マシンにインストールしたくないので、代わりに関連する gem ファイルをクックブックのリソースとして。
私はこのコードを使用しています
node["chef_gems"].each do |pkg, attrs|
gem_file = "#{pkg}-#{attrs["version"]}.gem"
dest_gem_file = "#{Chef::Config['file_cache_path']}/#{gem_file}"
cookbook_file "#{dest_gem_file}" do
source "gems/#{gem_file}"
end
if File.exist?("#{dest_gem_file}")
chef_gem pkg do
source "#{dest_gem_file}"
action :install
end
end
end
私が直面している問題
- 現在、File.exist? のため、これには 2 つのシェフの実行が必要です。チェックしますが、それがないと、コンパイル フェーズ中にファイルが存在しないため、コンパイルに失敗します。これを達成するためのより簡単な方法はありますか?
- これらの gem の一部には依存関係があるため、デフォルトでアルファベット順になっているように見える順序が重要です。私はソート順序キー (醜い) を介して順序を強制する道をたどろうとしていますが、より良い方法があるかどうか疑問に思っていました。
- 振り返ってみると、これは非常に複雑に思えます。運用サーバーに開発ツールをインストールせずに、宝石とその依存関係をインストールするという目標を達成するためのより簡単な戦略はありますか?
File.exist? のない元のエラーは次のとおりです。小切手
Starting Chef Client, version 11.4.0
resolving cookbooks for run list: ["cis-rhel", "ec2-hostname-rhel", "chef-client", "cassandra"]
Synchronizing Cookbooks:
<REDACTED>
Compiling Cookbooks...
[2013-10-16T18:45:01-04:00] WARN: Cloning resource attributes for user[<REDACTED>] from prior resource (CHEF-3694)
<REDACTED>
[2013-10-16T18:45:01-04:00] WARN: Current user[cassandra]: /var/chef/cache/cookbooks/cassandra/recipes/user.rb:23:in `from_file'
Recipe: cassandra::packages
* chef_gem[cassandra-cql] action install
================================================================================
Error executing action `install` on resource 'chef_gem[cassandra-cql]'
================================================================================
Gem::Exception
--------------
Cannot load gem at [/var/chef/cache/cassandra-cql-1.1.4.gem] in /
Cookbook Trace:
---------------
/var/chef/cache/cookbooks/cassandra/recipes/packages.rb:36:in `block in from_file'
/var/chef/cache/cookbooks/cassandra/recipes/packages.rb:29:in `each'
/var/chef/cache/cookbooks/cassandra/recipes/packages.rb:29:in `from_file'
/var/chef/cache/cookbooks/cassandra/recipes/default.rb:23:in `from_file'
Resource Declaration:
---------------------
# In /var/chef/cache/cookbooks/cassandra/recipes/packages.rb
36: chef_gem pkg do
37: source "#{dest_gem_file}"
38: action :install
39: end
40: # end
Compiled Resource:
------------------
# Declared in /var/chef/cache/cookbooks/cassandra/recipes/packages.rb:36:in `block in from_file'
chef_gem("cassandra-cql") do
provider Chef::Provider::Package::Rubygems
action [:install]
retries 0
retry_delay 2
package_name "cassandra-cql"
source "/var/chef/cache/cassandra-cql-1.1.4.gem"
cookbook_name "cassandra"
recipe_name "packages"
end
================================================================================
Recipe Compile Error in /var/chef/cache/cookbooks/cassandra/recipes/default.rb
================================================================================
Gem::Exception
--------------
chef_gem[cassandra-cql] (cassandra::packages line 36) had an error: Gem::Exception: Cannot load gem at [/var/chef/cache/cassandra-cql-1.1.4.gem] in /
Cookbook Trace:
---------------
/var/chef/cache/cookbooks/cassandra/recipes/packages.rb:36:in `block in from_file'
/var/chef/cache/cookbooks/cassandra/recipes/packages.rb:29:in `each'
/var/chef/cache/cookbooks/cassandra/recipes/packages.rb:29:in `from_file'
/var/chef/cache/cookbooks/cassandra/recipes/default.rb:23:in `from_file'
Relevant File Content:
----------------------
/var/chef/cache/cookbooks/cassandra/recipes/packages.rb:
29: node["cassandra"]["chef_gems"].each do |pkg, attrs|
30: gem_file = "#{pkg}-#{attrs["version"]}.gem"
31: dest_gem_file = "#{Chef::Config['file_cache_path']}/#{gem_file}"
32: cookbook_file "#{dest_gem_file}" do
33: source "gems/#{gem_file}"
34: end
35: # if File.exist?("#{dest_gem_file}")
36>> chef_gem pkg do
37: source "#{dest_gem_file}"
38: action :install
39: end
40: # end
41: end
42:
43: # Some distributed packages of Cassandra start the service in their
44: # postinstall; keep them all equal and a restart can be done after the configs
45: # are written on the first run. Added difficulty: they also come with init
[2013-10-16T18:45:01-04:00] ERROR: Running exception handlers
[2013-10-16T18:45:02-04:00] FATAL: Saving node information to /var/chef/cache/failed-run-data.json
[2013-10-16T18:45:02-04:00] ERROR: Exception handlers complete
Chef Client failed. 0 resources updated
[2013-10-16T18:45:02-04:00] FATAL: Stacktrace dumped to /var/chef/cache/chef-stacktrace.out
[2013-10-16T18:45:02-04:00] FATAL: Gem::Exception: chef_gem[cassandra-cql] (cassandra::packages line 36) had an error: Gem::Exception: Cannot load gem at [/var/chef/cache/cassandra-cql-1.1.4.gem] in /