More Related Content
Similar to ChefとPuppetの比較 (20)
More from Sugawara Genki (20)
ChefとPuppetの比較
- 2. 自己紹介
菅原 元気 (@sgwr_dts / id:winebarrel)
白金台のほうから来ました
● クックパッド株式会社勤務
● インフラエンジニア
● Ruby・AWS関連ツールを公開しています
○ https://bitbucket.org/winebarrel/
○ https://github.com/winebarrel/
- 14. クライアント側の機能の比較
ディレクトリ構成
Puppet(クックパッドの場合)
├── lib
├── manifests
├── modules
│ ├── apache
│ │ ├── files
│ │ ├── manifests
│ │ └── templates
│ ├── nginx
│
├── roles
│ ├── app_server
│ │ ├── files
│ │ ├── manifests
│ │ └── templates
│ ├── db_server
│ │ ├── manifests
│ │ └── templates
│
└── types
Chef
├── cookbooks
│ ├── apache
│ │ ├── attributes
│ │ ├── definitions
│ │ ├── files
│ │ ├── libraries
│ │ ├── providers
│ │ ├── recipes
│ │ ├── resources
│ │ └── templates
│ └── nginx
│ ├── attributes
│ ├── definitions
│ ├── files
│ ├── libraries
│ ├── providers
│ ├── recipes
│ ├── resources
│ └── templates
├── data_bags
├── nodes
│ ├── app-001.json
│ └── db-001.json
├── roles
│ ├── app.json
│ └── db.json
├── site-cookbooks
└── solo.rb
- 16. クライアント側の機能の比較
モジュール(クックブック)とロール
Puppet
# manifest
class nginx {
package { 'nginx':
ensure => '1.2.2.1',
}
service { 'nginx':
ensure => running,
enable => true,
require => Package['nginx'],
}
file { '/etc/nginx/enginx.conf':
ensure => present,
source => template('...'),
owner => 'root,
...
notify => Service['nginx'],
}
}
# role
class app {
include nginx
file { '/etc/hosts':
...
}
}
Chef
# recipe
package 'nginx' do
action :install
version '1.2.2.1'
end
service 'nginx' do
action { :enable, :start }
end
template '/etc/nginx/nginx.conf' do
source 'nginx.conf.erb'
owner 'root'
mode 0644
notifies :reload , 'service[nginx]'
end

# role: app.json
{
"run_list": [
"role[nginx]"
]
}
- 17. クライアント側の機能の比較
モジュール(クックブック)とロール
Puppet
# カスタムタイプ
define sysctl($value) {
exec { "exec_sysctl_$name":
command => "sysctl -w $name=$value}",
unless => "sysctl -n ${name} |
fgrep -q $value",
path => '/bin:/sbin:/usr/sbin:/usr/bin',
}
# ...
sysctl { 'kernel.domainname':
value => 'example.com',
}
Chef
# カスタムリソース
define :sysctl do
bash "exec-sysctl-#{params[:name]}" do
code <<-EOS
sysctl -w #{params[:name]=#{params[:value]}
EOS
not_if <<-EOS
sysctl -n ${params[:name]} |
fgrep -q #{params[:value]}
EOS
end
end
# ...
sysctl 'kernel.domainname' do
value 'example.com'
end
- 26. クライアント側の機能の比較
Run Stage
● 適用順を制御できます
● Chefで必要になる機能ではないですね…
stage { 'first': before => Stage['main'] }
stage { 'last': require => Stage['main']
}
class {
'apt-keys': stage => first;
'sendmail': stage => main;
'apache': stage => last;
}