LoginSignup
12
8

More than 5 years have passed since last update.

Itamaeの今のところの個人的ベストプラクティス

Posted at

1. 公式のBest-Practiceを参考に

itamae g cookbook とか itamae g role とかできるようになったし
モジュール感という意味でも公式のが好き

ここまでで↓の状態
(公式ではroles/web.rbとなっているが、itamae g roleした状態にしたがう)

.
├── cookbooks
│   └── nginx
│       ├── default.rb
│       ├── files
│       │   └── etc
│       │       └── nginx
│       │           └── conf.d
│       │               └── static.conf
│       └── templates
│           └── etc
│               └── nginx
│                   └── conf.d
│                       └── dynamic.conf
└── roles
    └── web
        └── default.rb
        └── files
        └── templates

2. nodeはYAMLで

JSONよりYAMLの方がconfigurationには適してるのでYAMLで。
ここまでで↓の状態

.
├── cookbooks
│   └── nginx
│       ├── default.rb
│       ├── files
│       │   └── etc
│       │       └── nginx
│       │           └── conf.d
│       │               └── static.conf
│       └── templates
│           └── etc
│               └── nginx
│                   └── conf.d
│                       └── dynamic.conf
└── roles
│   └── web
│       └── default.rb
│       └── files
│       └── templates
└── nodes
    └── web-staging.yml

3. nodeにroleを含める

だいたいnodeはroleと対応するので

$ bundle exec itamae local -y nodes/web-staging.yml roles/web/default.rb

とするのは冗長

以下を参考に、nodeにroleを含める。
なお、以下ではnode内でrecipeを指定しているが、recipeにすると自由度高くて
つい手抜きしたときにrole外のrecipeも追加したりしてごちゃつくのでroleで縛った方が好き
http://qiita.com/toritori0318/items/00ea2a75c8321aaf9ef6

ここまでで↓の状態。完成。

.
├── cookbooks
│   └── nginx
│       ├── default.rb
│       ├── files
│       │   └── etc
│       │       └── nginx
│       │           └── conf.d
│       │               └── static.conf
│       └── templates
│           └── etc
│               └── nginx
│                   └── conf.d
│                       └── dynamic.conf
└── roles
│   └── web
│       └── default.rb
│       └── files
│       └── templates
└── nodes
│   └── web-staging.yml
└── entry.rb
entry.rb
node['roles'] = node['roles'] || []
node['roles'].each do |role|
  include_recipe "roles/#{role}/default.rb"
end
web-staging.yml
roles:
  - app
nginx:
  worker_processes: 2
$ bundle exec itamae local -y nodes/web-staging.yml entry.rb
12
8
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
12
8