node の登録
Workstation から knife を使う場合
knife node create ${knode_fqdn} -e vim
node の FQDN が Chef Server から名前解決できる状況が必要(だと思われる)。また、この時点では Chef Server には実際の node との関連付けは行われていない。
node から knife configure を実行する場合
knife configure -i
を実行すると
WARNING: No knife configuration file found
Where should I put the config file? [/root/.chef/knife.rb]
Please enter the chef server URL: [http://debian.local:4000] https://${chefserver}
Please enter a name for the new user: [vagrant] admin
Please enter the existing admin name: [admin]
Please enter the location of the existing admin's private key: [/etc/chef/admin.pem]
Please enter the validation clientname: [chef-validator]
Please enter the location of the validation key: [/etc/chef/validation.pem]
Please enter the path to a chef repository (or leave blank):
Creating initial API user...
Please enter a password for the new user:
ERROR: Your private key could not be loaded from /etc/chef/admin.pem
Check your configuration file and ensure that your private key is readable
幾つかの質問を Enter で答えると knife.rb が作成される。(root 権限で実行した場合に /root/.chef 以下に生成される。)ので、環境に応じて適宜修正する。以下、自分が行った修正点。
Please enter the chef server URL: [http://debian.local:4000] https://${chefserver}
Chef Server の URL を指定する。Chef 10 までは http://${chefserver}:4000 だったのでその名残りが残っているが、Chef 11 からは https://${chefserver} を設定する。
Please enter a name for the new user: [vagrant] admin
Chef Server の WebUI に設定されているユーザーを指定する。デフォルトで Chef Server に存在する admin ユーザーを指定する。
Please enter the location of the existing admin's private key: [/etc/chef/admin.pem]
admin ユーザーの秘密鍵のパスを指定。秘密鍵自体は [Users] → [List] → [admin] ユーザーの [Edit] をクリックして、[Regenerate Private Key] にチェックをして生成した秘密鍵を利用した。
Please enter the location of the validation key: [/etc/chef/validation.pem]
varidation.pem ファイルのパスを指定する。これは Chef Server の [Clients] → [chef-validator] の [Edit] をクリックして [Private Key] にチェックをして生成した秘密鍵を利用した。尚、上記はあくまでも knife から Chef Server にアクセスする為に必要な設定。(という認識。)なので Chef Server から node に対する認識は別途行った。
client.rb を設定する
/etc/chef/client.rb を作成する。
log_level :info
log_location STDOUT
chef_server_url 'https://${chefserver}'
validation_client_name 'chef-validator'
chef-client を実行する
chef-client を実行し、正常に Chef Server に接続出来ると client.pem が生成されている。
root@debian:/etc/chef# pwd
/etc/chef
root@debian:/etc/chef# ls -l
total 20
-rw------- 1 root root 1675 Apr 21 06:22 client.pem
-rw------- 1 root root 1679 Apr 21 02:35 client.pem.bk
-rw-r--r-- 1 root root 133 Apr 21 02:35 client.rb
-rw-r--r-- 1 root root 1112 Apr 21 06:24 hoge.txt
-rw-r--r-- 1 root root 1679 Apr 21 02:28 validation.pem
root@debian:/etc/chef#
また、Chef Server の nodes にホスト((node)が登録されている。
尚、client.pem を置き換えて接続しようとすると...
[2013-04-21T06:24:34+00:00] INFO: HTTP Request Returned 409 Conflict: Client already exists
================================================================================
Chef encountered an error attempting to create the client "debian.local"
================================================================================
Authorization Error:
--------------------
Your validation client is not authorized to create the client for this node (HTTP 403).
こんなエラーが出てしまう。この場合には、Chef Server の nodes と clients に既に登録されているホスト名を削除すると回避出来る。