4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

AWS OpsWorks のデバグ

4
Last updated at Posted at 2019-01-15

チラ裏。AWS OpsWorks を使ってインスタンスへの chef (または puppet) 適用を自動で行うことができる。できるのは良いのだが、失敗した時に理由を追うのに困るのでログの場所、および簡単な再実行方法をメモ。

cloud-init のログおよび再実行

いきなり蛇足: OpsWorks だけでなく、cloud-init (UserData) を使って起動時になにか処理をしている場合、cloud-init のログも見るべし。

/var/log/cloud-init.log

cloud-init の再実行ついては以前 cloud-init のスクリプトを reboot せずに再実行するには に書いた。

OpsWorks のログ

OpsWorks のログは、終われば AWS コンソールから見れるが、進行中はすぐに反映されないので、インスタンスに ssh してログを tail -F で追う。

OpsWorks Chef の場合のパスはこちら。

sudo tail -F /var/lib/aws/opsworks/chef/yyyy-MM-dd-hh-mm-ss-..log

AWS OpsWorks Stacks のライフサイクルイベント のそれぞれでログファイルが分かれているようだが中を見てみないとどれがどれか分からない。

  • setup
  • configure
  • deploy

先頭行に Command: setup with のように setup か configure か deploy かなどが書いてあるので、どのログファイルがどのイベントに対するものなのかはそこをみればわかる(ような気配がする)

$ less /var/lib/aws/opsworks/chef/yyyy-MM-dd-hh-mm-ss-..log
[2019-01-15T19:55:07+09:00] INFO: AWS OpsWorks instance xxx-xxx-xxx-xxx, Agent version 4033-20181126114950, Command: setup with id xxx-xxx-xxx-xxx
...
...

OpsWorks Agent のログ

OpsWorks Agent が実行した chef コマンドのログなどはこちら

/var/log/aws/opsworks/opsworks-agent.process_command.log

このログを chef-client で grep すると、chef-client を手動実行するためのコマンドが取れるので、うまく attribs.json などを見つければ、それで何度も試行錯誤できるようになる。例えばこんなの。

env HOME=/root sudo /opt/aws/opsworks/current/bin/chef_command_wrapper.sh -s /opt/chef/bin/chef-client -j /var/chef/runs/xxx-xxx-xxx-xxx/attribs.json -c /var/chef/runs/xxx-xxx-xxx-xxx/client.rb -L /var/chef/runs/xxx-xxx-xxx-xxx/chef.log

これに -o オプションで runlist を追加すれば実行できる。

cookbooks は標準では以下のパスにあるので、一時的に弄りたい時はそこをいじる。

/var/chef/cookbooks/

attributes は -j オプションで指定されている attribs.json に書いてあるので、一時的に弄りたい時はそこをいじる。

参考

以下のページがとても参考になりました。Thanks.

4
4
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
4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?