組み込みロールを備えたChef Cookbook
質問
私はChef Cookbookを作成しました。私の主な問題は、他のクックブックからのレシピがランダムな順序で実行されることです。vagrantファイル内のこれらのレシピの実行を指定した場合:
chef.add_recipe "gitlab::core_prereq"
chef.add_recipe "postfix"
chef.add_recipe "gitlab::users_prereq"
chef.add_recipe "rvm::vagrant"
chef.add_recipe "rvm::system"
chef.add_recipe "ohai"
chef.add_recipe "nginx"
chef.add_recipe "gitlab::python_tools_prereq"
chef.add_recipe "gitlab::gitolite_prereq"
chef.add_recipe "gitlab::gitlab_install"
.
すべてがうまく機能しますが、この仕様をレシピに入れてもらえます。
どうすればこれを解決することができますか?役割を使うべきですか?レシピ内で役割を指定できる場合は、Chefドキュメントから入手しません。
解決
あなたのすべてのレシピをクリーンマシンにインストールできるわけではありません。しかし彼らはあるべきです。いくつかのレシピ "A"にいくつかの前提条件がある場合は、その必要なレシピをinclude_recipe
を使用してレシピ "A"に追加する必要があります。
あなたの場合私は gitlab :: gitlab_install を必要とします gitlab :: gitolite_prealq と gitlab :: python_tools_prealq 。それはあなたがあなたのcookbooks/gitlab/recipes/gitlab_install.rb
に追加するべきです:
.
incude_recipe 'gitlab::gitolite_prereq'
incude_recipe 'gitlab::python_tools_prereq'
このように他のクックブックからレシピを含めることもできます。試験のために Ohai の場合、 rvm :: system 。cookbooks/ohai/recipes/default.rb
:に追加します
.
incude_recipe 'rvm::system'
とcookbooks/ohai/metadata.rb
に追加:
.
depends 'rvm'
このようにして、すべてのレシピを正確な順序で書く必要はなく、すべての依存関係を書く必要はありません。