エロサイトの作り方

2013年11月から勉強しながらエロサイトを作っています。

Ansibleで環境構築(5) - NewRelicの設定

前回みたいに一度がでかいテーマになると書くのに時間がかかって面倒になるので、小刻みに書くようにします。というわけで、NewRelic

./roles/common/tasks/main.yml

- include: newrelic.yml

commonロールのmain.ymlの最後に追加。

./roles/common/vars/main.yml

newrelic_license_key: 自分のライセンスキーを入れる

NewRelicのライセンスキーは変数にしておきます。

./roles/common/templates/etc/newrelic/nrsysmond.cfg.j2

license_key={{ newrelic_license_key }}

loglevel=info

logfile=/var/log/newrelic/nrsysmond.log

NewRelicの設定ファイルのテンプレート。あんまり書くことがない。

template配下は、後でごちゃごちゃしないように配置先のディレクトリ階層をそのままにしておきます。

./roles/common/files/etc/apt/sources.list.d/newrelic.list

deb http://apt.newrelic.com/debian/ newrelic non-free

NewRelicのapt用ソースリスト。

テンプレートじゃないファイルはfiles配下に置くというルールが推奨らしい。

この内容なら直接コマンドで書いてもよかったかも。

./roles/common/tasks/newrelic.yml

---
- name: add newrelic repo to apt sources
  action: copy src=etc/apt/sources.list.d/newrelic.list dest=/etc/apt/sources.list.d/newrelic.list
  tags: newrelic

- name: add newrelic key to the apt repo
  action: apt_key url=http://download.newrelic.com/548C16BF.gpg state=present
  tags: newrelic

- name: update package list
  action: apt update_cache=yes
  tags: newrelic

- name: ensure newrelic-sysmond is installed
  action: apt pkg=newrelic-sysmond state=present
  tags: newrelic

- name: update newrelic nrsysmond.cfg
  template: src=etc/newrelic/nrsysmond.cfg.j2 dest=/etc/newrelic/nrsysmond.cfg owner=root group=root
  tags: newrelic

- name: ensure proper permissions on nrsysmond.cfg file
  action: file path=/etc/newrelic/nrsysmond.cfg mode=0640 owner=root group=newrelic
  tags: newrelic

- name: start newrelic-sysmond
  service: name=newrelic-sysmond state=started
  tags: newrelic

どこぞからパクってきた記述のほぼまんまなのですが、これで動きましたよって記録ということで。