LoginSignup
15
13

More than 5 years have passed since last update.

OpsWorksでcookbookをEC2上でデバッグする方法

Posted at

はじめに

OpsWorksでsupermarketのcookbookを使いたい場合、cookbookの設定が複雑だと、
設定がうまくいかない場合があり、何度もレシピの再実行が必要で、
またその再実行にかなり時間がかかります。

このドキュメントで、EC2上でのcookbook/recipeのデバッグTipsをメモしていきます。

環境

Chef 11.10
Amazon Linux 2015.03

手順

cookbookのデプロイ場所へ移動する

$ sudo su
# cd /ops/aws/opsworks/current

デバッグ用のGemライブラリをインストールする

Gemfileに以下を追加する

/ops/aws/opsworks/current/Gemfile
gem 'pry'
gem 'pry-byebug'
gem 'pry-doc'
gem 'pry-stack_explorer'

インストールする

# /ops/aws/opsworks/local/bin/bundle install

レシピを編集する

レシピは、site-cookbooksフォルダではなく、
merged-cookbooks下のレシピを編集します。

cd /ops/aws/opsworks/current/merged-cookbooks

デバッグを開始したいコードに以下を挿入する

binding.pry

chef-clientでレシピを実行する

jsonはご自身の環境のものに差し替えてください

/opt/aws/opsworks/current/bin/chef-client -j /var/lib/aws/opsworks/chef/2015-06-22-12-05-24-01.json -c /var/lib/aws/opsworks/client.stage2.rb -o cookbook_name::recipe_name

/var/lib/aws/opsworks/client.stage2.rb 内で、
環境変数がクリアされます。
私の場合、レシピの先頭に以下を追加しました。

default.rb
ENV['GEM_PATH'] = '/opt/aws/opsworks/current/vendor/bundle/ruby/2.0.0'
ENV['GEM_HOME'] = '/opt/aws/opsworks/current/vendor/bundle/ruby/2.0.0/gems'
ENV['BUNDLE_GEMFILE'] = '/opt/aws/opsworks/current/Gemfile'
15
13
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
15
13