「Chef」の版間の差分

提供: FreeBSD入門
移動: 案内検索
(関連項目)
行7: 行7:
  
 
== 概要 ==
 
== 概要 ==
 +
Chef は、レシピを Ruby で記述することができます。たくさんの同じノードをコードで管理できます。
 +
以下にレシピの例を示します。
 +
<syntaxhighlight lang="ruby">
 +
package "git" do
 +
action :install
 +
end
 +
</syntaxhighlight>
 +
== Chef入門 ==
 
* [[Chefのインストール]]
 
* [[Chefのインストール]]
 +
* [[Chef knifeコマンド]]
 
* [[chef-solo Hello World]]
 
* [[chef-solo Hello World]]
 +
* [[Chef クックブックの作成]]
 
* [[Chef ディレクトリの作成]]
 
* [[Chef ディレクトリの作成]]
 +
* [[Chef Soloでパッケージをインストールする]]
 
* [[Chef ファイルの作成]]
 
* [[Chef ファイルの作成]]
 +
== Chefの動作イメージ ==
 +
[[Chef]]には、以下の2種類の動作形態があります。
 +
* Chef Server/Chef Client(chef-client)
 +
* Chef Solo
  
== インストール ==
+
Chef Server / Chef Client は、クライアント・サーバモデルです。 Chef Solo は、スタンドアロンのモデルです。
{{ports|/usr/ports/sysutils/rubygem-chef|rubygem-chef}}
+
=== Chef Server / Chef Client ==
{{ports|/usr/ports/devel/rubygem-rake|rubygem-rake}}
+
クライアント・サーバモデルでは、 Chef Server は、構成情報の管理を行い、Web UI, Chef Server API を提供します。
== 設定 ==
+
Chefの設定対象の各ノードでは、chef-client が動作します。chef-clientは、Chef Server に問い合わせを行い、インストールなどの作業を実行します。chef-clientは、ユーザがコマンドで起動する方法と cron などで自動で実行することができます。クックブックの登録は、knifeコマンドを通じで行います。
=== /etc/chef/solo.rb ===
+
=== Chef Solo ===
solo.rbの設定ファイルを作成します。cookbookのパスを指定します。
+
Chef Solo は、スタンドアロンで動作するため、Chef Server が不要です。小規模な環境で利用します。
<syntaxhighlight lang="bash">
+
== Chefがサポートする環境 ==
sudo mkdir /etc/chef
+
Chef Clientは、様々な環境で動作します。
sudo vim /etc/chef/solo.rb
+
* FreeBSD
</syntaxhighlight>
+
* Ubuntu
<syntaxhighlight lang="bash">
+
* Red Hat
% cat /etc/chef/solo.rb
+
* OS X
cookbook_path ["/home/user/chef/test/cookbooks"]
+
* etc ...
</syntaxhighlight>
+
== Chef の特徴 ==
== 使い方 ==
+
* 設定を Ruby で記述します。
=== バージョンの確認 ===
+
* 記述した順番に処理が実行されます。
<syntaxhighlight lang="bash">
+
== Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully ==
% chef-solo -v
+
Chef: 11.6.0
+
% knife -v
+
Chef: 11.6.0
+
</syntaxhighlight>
+
 
+
=== knifeのセットアップ ===
+
<syntaxhighlight lang="bash">
+
% knife configure
+
WARNING: No knife configuration file found
+
Where should I put the config file? [/home/user/.chef/knife.rb]
+
Please enter the chef server URL: [https://vm2.local:443]
+
Please enter an existing username or clientname for the API: [user]
+
Please enter the validation clientname: [chef-validator]
+
Please enter the location of the validation key: [/etc/chef-server/chef-validator.pem]
+
Please enter the path to a chef repository (or leave blank):
+
*****
+
 
+
You must place your client key in:
+
  /home/user/.chef/user.pem
+
Before running commands with Knife!
+
 
+
*****
+
 
+
You must place your validation key in:
+
  /etc/chef-server/chef-validator.pem
+
Before generating instance data with Knife!
+
 
+
*****
+
Configuration file written to /home/user/.chef/knife.rb
+
</syntaxhighlight>
+
 
+
=== chefクックブックの作成 ===
+
<syntaxhighlight lang="bash">
+
% knife cookbook create test -o cookbooks
+
** Creating cookbook test
+
** Creating README for cookbook: test
+
** Creating CHANGELOG for cookbook: test
+
** Creating metadata for cookbook: test
+
</syntaxhighlight>
+
 
+
生成されたファイルは、以下の通りです。
+
<syntaxhighlight lang="bash">
+
% ls cookbooks/test
+
CHANGELOG.md  attributes/  files/        metadata.rb  recipes/      templates/
+
README.md    definitions/  libraries/    providers/    resources/
+
</syntaxhighlight>
+
 
+
=== recipes/default.rb ===
+
logでメッセージだけを表示する例です。
+
<syntaxhighlight lang="bash">
+
% cat cookbooks/test/recipes/default.rb
+
#
+
# Cookbook Name:: test
+
# Recipe:: default
+
#
+
# Copyright 2013, YOUR_COMPANY_NAME
+
#
+
# All rights reserved - Do Not Redistribute
+
#
+
log "Hello Chef"
+
</syntaxhighlight>
+
 
+
=== chef-soloの実行 ===
+
<syntaxhighlight lang="bash">
+
% cd cookbooks
+
% sudo chef-solo -o test
+
Starting Chef Client, version 11.6.0
+
[2013-12-07T18:42:13+09:00] WARN: Run List override has been provided.
+
[2013-12-07T18:42:13+09:00] WARN: Original Run List: []
+
[2013-12-07T18:42:13+09:00] WARN: Overridden Run List: [recipe[test]]
+
Compiling Cookbooks...
+
Converging 1 resources
+
Recipe: test::default
+
  * log[Hello Chef] action write
+
 
+
Chef Client finished, 1 resources updated
+
</syntaxhighlight>
+
 
+
=== Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully ===
+
 
chef-solo を起動すると、即効で瞬殺されました。
 
chef-solo を起動すると、即効で瞬殺されました。
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
行152: 行87:
 
** Creating metadata for cookbook: test
 
** Creating metadata for cookbook: test
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
== エラー ==
 +
下記のエラーがでた場合は、 /etc/chef/solo.rb に ssl_verify_mode :verify_peer を書き足します。
 +
<syntaxhighlight lang="bash">
 +
[2015-05-29T23:52:43+09:00] WARN:
 +
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 +
SSL validation of HTTPS requests is disabled. HTTPS connections are still
 +
encrypted, but chef is not able to detect forged replies or man in the middle
 +
attacks.
 +
 +
To fix this issue add an entry like this to your configuration file:
 +
 +
```
 +
  # Verify all HTTPS connections (recommended)
 +
  ssl_verify_mode :verify_peer
  
 +
  # OR, Verify only connections to chef-server
 +
  verify_api_cert true
 +
```
 +
 +
To check your SSL configuration, or troubleshoot errors, you can use the
 +
`knife ssl check` command like so:
 +
 +
```
 +
  knife ssl check -c /etc/chef/solo.rb
 +
```
 +
 +
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 +
 +
Starting Chef Client, version 11.14.6
 +
Compiling Cookbooks...
 +
Converging 0 resources
 +
 +
Running handlers:
 +
Running handlers complete
 +
Chef Client finished, 0/0 resources updated in 3.947692374 seconds
 +
</syntaxhighlight>
 
== 関連項目 ==
 
== 関連項目 ==
 
* [[デプロイツール]]
 
* [[デプロイツール]]
 
{{chef}}
 
{{chef}}
<!-- vim: fileencoding=utf-8 filetype=mediawiki -->
+
<!-- vim: fileencoding=utf-8 filetype=mediawiki
 +
-->

2015年5月29日 (金) 23:59時点における版

Chef とは、インフラストラクチャの管理をコードによって行う、自動化するためのプラットフォームです。

読み方

Chef
しぇふ

概要

Chef は、レシピを Ruby で記述することができます。たくさんの同じノードをコードで管理できます。 以下にレシピの例を示します。

package "git" do
	action :install
end

Chef入門

Chefの動作イメージ

Chefには、以下の2種類の動作形態があります。

  • Chef Server/Chef Client(chef-client)
  • Chef Solo

Chef Server / Chef Client は、クライアント・サーバモデルです。 Chef Solo は、スタンドアロンのモデルです。

= Chef Server / Chef Client

クライアント・サーバモデルでは、 Chef Server は、構成情報の管理を行い、Web UI, Chef Server API を提供します。 Chefの設定対象の各ノードでは、chef-client が動作します。chef-clientは、Chef Server に問い合わせを行い、インストールなどの作業を実行します。chef-clientは、ユーザがコマンドで起動する方法と cron などで自動で実行することができます。クックブックの登録は、knifeコマンドを通じで行います。

Chef Solo

Chef Solo は、スタンドアロンで動作するため、Chef Server が不要です。小規模な環境で利用します。

Chefがサポートする環境

Chef Clientは、様々な環境で動作します。

  • FreeBSD
  • Ubuntu
  • Red Hat
  • OS X
  • etc ...

Chef の特徴

  • 設定を Ruby で記述します。
  • 記述した順番に処理が実行されます。

Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully

chef-solo を起動すると、即効で瞬殺されました。

% chef-solo -o test
[2013-12-07T18:31:57+09:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef
run process exited unsuccessfully (exit code 1)

意味がこれだとわからないため、デバッグモードでchef-soloを起動しました。

% chef-solo -o test -l debug
[2013-12-07T18:33:21+09:00] INFO: Forking chef instance to converge...
[2013-12-07T18:33:21+09:00] DEBUG: Fork successful. Waiting for new chef pid: 38689
[2013-12-07T18:33:21+09:00] DEBUG: Forked instance now converging
[2013-12-07T18:33:21+09:00] DEBUG: Creating directory /var/chef
[2013-12-07T18:33:21+09:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef
run process exited unsuccessfully (exit code 1)

/var/chef に一般ユーザー権限で書き込もうとして、朽ち果てています。 /var/chef/cache/ にキャッシュファイルが作りたかったようです。 sudoをつけて実行すれば、書き込めます。

% sudo chef-solo -o test -l debug

git

git clone git://github.com/opscode/chef-repo.git
% cd ./chef-repo/
% rake new_cookbook COOKBOOK=test
***WARN: rake new_cookbook is deprecated.
Please use 'knife cookbook create COOKBOOK' command.***
** Creating cookbook test
mkdir -p /home/usre/chef/test/chef-repo/cookbooks/test/attributes
mkdir -p /home/usre/chef/test/chef-repo/cookbooks/test/recipes
mkdir -p /home/usre/chef/test/chef-repo/cookbooks/test/definitions
mkdir -p /home/usre/chef/test/chef-repo/cookbooks/test/libraries
mkdir -p /home/usre/chef/test/chef-repo/cookbooks/test/resources
mkdir -p /home/usre/chef/test/chef-repo/cookbooks/test/providers
mkdir -p /home/usre/chef/test/chef-repo/cookbooks/test/files/default
mkdir -p /home/usre/chef/test/chef-repo/cookbooks/test/templates/default
** Creating README for cookbook: test
** Creating metadata for cookbook: test

エラー

下記のエラーがでた場合は、 /etc/chef/solo.rb に ssl_verify_mode :verify_peer を書き足します。

[2015-05-29T23:52:43+09:00] WARN:
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
SSL validation of HTTPS requests is disabled. HTTPS connections are still
encrypted, but chef is not able to detect forged replies or man in the middle
attacks.
 
To fix this issue add an entry like this to your configuration file:
 
```
  # Verify all HTTPS connections (recommended)
  ssl_verify_mode :verify_peer
 
  # OR, Verify only connections to chef-server
  verify_api_cert true
```
 
To check your SSL configuration, or troubleshoot errors, you can use the
`knife ssl check` command like so:
 
```
  knife ssl check -c /etc/chef/solo.rb
```
 
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 
Starting Chef Client, version 11.14.6
Compiling Cookbooks...
Converging 0 resources
 
Running handlers:
Running handlers complete
Chef Client finished, 0/0 resources updated in 3.947692374 seconds

関連項目