Chef Server 環境構築手順
1. はじめに
本文書では、"Chef Server" を使用した Chef環境の作り方について書いています。
Chef Server - Chef Workstation - Chef Node の 環境は、Chef の最も基本的な使用方法です。
作りたい環境
それぞれ LinuxサーバA/B/C の FQDN名、役割は以下の通りです。
- LinuxサーバA: sjchefs01.cent7.local - Chef Server
- LinuxサーバB: sjchefw01.cent7.local - Chef Workstation
- LinuxサーバC: sjchefn01.cent7.local - Chef Node
要件
- お互いにほぼ同じ時間である必要があります。NTPなどで事前に同期をとっておくのがオススメです。
- お互いにそれぞれの名前を解決ができる必要があります
- Chef Workstation とChef Nodeは、Chef Serverに対して https通信 できる必要があります
- Chef Workstation は、Linux の Chef Nodeに対して ssh通信 できる必要があります
- 本文書では、3サーバとも Cent0S 7.1 を使用しています。こちらを見ていただくとわかりますが、Chef Server はRedHat系OS か Ubuntu系OS に導入可能です。Windows Server は Chef Server になることはできません。
- 導入手順がシンプルになるので、本文書では上記3サーバがインターネットに接続できることを前提とします。Chef 自体はサーバがインターネットに接続していなくても利用することが可能です。
注意事項
2016/10/24時点での情報を元に作成しています。
最新の情報は 公式 LEARN CHEF / Install the Chef Server あたりを参照してください。
また、本手順は IBM Bluemix Infrastructure (旧SoftLayer)上で検証しています。
2. Chef Server セットアップ
Chef Server の主な役割は、Cookbook や Node、Roleなどを管理すること、https経由で接続してきた Chef Client に role や enviroment に基づいて適切な Cookbook を渡すことです。Chef Server になるサーバには、Chef Server のモジュールを導入します。
Chef Server は本文書執筆時の最新である 12.9
を使用します。
また、本セクションでは、以下の公式サイトを参照しています。
LEARN CHEF / Install the Chef Server
補足
Chef Server の "additional Chef features" を使う場合、その Chef Server で管理する Chef Node が25台までであれば無料で使えます。それ以上使用する場合は有料になります。
参考:CHEF DOWNLOADS / Chef Server
Chef 11 まで無償提供されていた WebUI の機能が、12 からは Management Console として "additional Chef features" 扱いになっていることに注意が必要です。Chef Node が26台以上いるような環境でも無料で使用したい場合は、Chef Server の Management Console は導入しないで、knife や chef-server-ctl などの CUI で Chef Server を操作する必要があります。
本文書は、Management Console を追加導入しません。
Chef Server 導入
Chef Server の Coreパッケージを ダウンロードして、導入します。
ダウンロード用URL は以下に記載されています。
CHEF DOWNLOAD / Chef Server
[root@sjchefs01 ~]# rpm -Uvh https://packages.chef.io/stable/el/7/chef-server-core-12.9.1-1.el7.x86_64.rpm
Retrieving https://packages.chef.io/stable/el/7/chef-server-core-12.9.1-1.el7.x86_64.rpm
warning: /var/tmp/rpm-tmp.PhCrHe: Header V4 DSA/SHA1 Signature, key ID 83ef826a: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:chef-server-core-12.9.1-1.el7 ################################# [100%]
導入自体はこれで完了です。
Chef Server 初期構成
導入後、chef-server-ctl
コマンドで Chef Server の初期構成が必要です。
初期化のみならず、Chef Server を CUI で操作する際には chef-server-ctl
コマンドをよく使用します。
LEARN CHEF / chef-server-ctl (executable)
[root@sjchefs01 ~]# chef-server-ctl reconfigure
Starting Chef Client, version 12.14.98
resolving cookbooks for run list: ["private-chef::default"]
Synchronizing Cookbooks:
- apt (2.9.2)
- yum (3.13.0)
- openssl (6.0.0)
- packagecloud (0.2.5)
- private-chef (0.1.0)
- enterprise (0.10.1)
- runit (1.6.0)
Installing Cookbook Gems:
Compiling Cookbooks...
(中略)
Chef Client finished, 393/468 resources updated in 03 minutes 26 seconds
Chef Server Reconfigured!
このコマンドの標準出力を見ていると、Chef Server自身の初期構成にも Chef Client を使っていることが分かります。
ユーザ/組織の作成
組織は、Chef Server 内を論理分割する単位と思っていただけると良いと思います。Cookbook は組織内で一意である必要があります。
ユーザは Chef Server の WebUI にログインする際に用いるユーザです。WebUI がない環境では、knife コマンド経由で Chef Server を操作しますが、knifeコマンド使用時の認証は Chef Workstation ローカルに保管した 鍵で行われます。ぶっちゃけ、WebUI がない環境では、1つの組織に1つのユーザがあれば良い気がします。。
以下の例では ユーザ名 kentarok、組織名 test で作成しています。
[root@sjchefs01 ~]# mkdir -p /etc/opscode/test/
[root@sjchefs01 ~]# chef-server-ctl user-create kentarok FIRST_NAME LAST_NAME email@gmail.com 'xxxxxxxx' --filename /etc/opscode/test/kentarok.pem
[root@sjchefs01 ~]# chef-server-ctl org-create test 'Test Company' --association_user kentarok --filename /etc/opscode/test/test-validator.pem
[root@sjchefs01 ~]# chef-server-ctl user-list
kentarok
pivotal
[root@sjchefs01 ~]# chef-server-ctl org-list
test
書式は以下の通りです。
USER_NAME.pem と ORGANIZAITON-validator.pem は あとで Chef Workstation を作る時に使いますので、scp や 中身をコピペするなどの方法でお手元に持ってきておいてください。
$ chef-server-ctl user-create USER_NAME FIRST_NAME LAST_NAME EMAIL 'PASSWORD' --filename USER_NAME.pem
$ chef-server-ctl org-create short_name 'full_organization_name' --association_user user_name --filename ORGANIZATION-validator.pem
これで必要最低限の Chef Server のセットアップが完了しました。
Chef Manage や Reporting など 追加で "Additional Chef Feature" を導入する場合は公式サイトを参照してください。
LEARN CHEF / Install the Chef Server
3. Chef Workstation セットアップ
Chef Workstation の主な役割は、knifeコマンド を使って Chef Server を操作すること、knifeコマンドを使って、Chef Node上の chef-client を起動すること、です。Chef Workstation になるサーバには Chef Development Kit (ChefDK) を導入します。
ChefDK は本文書執筆時の最新である 0.19.6
を使用します。
また、本セクションでは、以下の公式サイトを参照しています。
Install the Chef DK
補足
本文書では、Chef Workstation として Linuxサーバ を使用していますが、お手元の WindowsPC や Mac といったPC系の端末を Chef Workstation としてセットアップすることも可能です。(というか、そっちの方がメジャー?)
また、Chef Workstation は Chef Server と同じサーバに同居することも可能です。何らかの理由で、Chef Workstatin を WindowsPC や Mac にしたくなくて、Linuxサーバにしたい場合は、Chef Server と同居させると、管理する Linuxサーバ の数が減らせるのでオススメです。
このあたりの構成をどう選択するかの話は、また別の機会にしたいと思います。
Chef Development Kit 導入
Chef Server 同様、rpm コマンドを使って導入します。
ダウンロード用URL は以下に記載されています。
CHEF DOWNLOAD / Chef DK
[root@sjchefw01 ~]# rpm -Uvh https://packages.chef.io/stable/el/7/chefdk-0.19.6-1.el7.x86_64.rpm
Retrieving https://packages.chef.io/stable/el/7/chefdk-0.19.6-1.el7.x86_64.rpm
warning: /var/tmp/rpm-tmp.gEWes7: Header V4 DSA/SHA1 Signature, key ID 83ef826a: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:chefdk-0.19.6-1.el7 ################################# [100%]
Thank you for installing Chef Development Kit!
正しく導入されていることを確認します。後半で全ての component が succeeded になっていることを確かめてください。
[root@sjchefw01 ~]# chef verify
Running verification for component 'berkshelf'
Running verification for component 'test-kitchen'
Running verification for component 'tk-policyfile-provisioner'
Running verification for component 'chef-client'
Running verification for component 'chef-dk'
Running verification for component 'chef-provisioning'
Running verification for component 'chefspec'
Running verification for component 'generated-cookbooks-pass-chefspec'
Running verification for component 'rubocop'
Running verification for component 'fauxhai'
Running verification for component 'knife-spork'
Running verification for component 'kitchen-vagrant'
Running verification for component 'package installation'
Running verification for component 'openssl'
Running verification for component 'inspec'
Running verification for component 'delivery-cli'
Running verification for component 'git'
Running verification for component 'opscode-pushy-client'
Running verification for component 'chef-sugar'
.....................................
---------------------------------------------
Verification of component 'fauxhai' succeeded.
Verification of component 'kitchen-vagrant' succeeded.
Verification of component 'openssl' succeeded.
Verification of component 'delivery-cli' succeeded.
Verification of component 'test-kitchen' succeeded.
Verification of component 'rubocop' succeeded.
Verification of component 'inspec' succeeded.
Verification of component 'opscode-pushy-client' succeeded.
Verification of component 'berkshelf' succeeded.
Verification of component 'chefspec' succeeded.
Verification of component 'knife-spork' succeeded.
Verification of component 'git' succeeded.
Verification of component 'tk-policyfile-provisioner' succeeded.
Verification of component 'chef-dk' succeeded.
Verification of component 'chef-client' succeeded.
Verification of component 'chef-sugar' succeeded.
Verification of component 'package installation' succeeded.
Verification of component 'generated-cookbooks-pass-chefspec' succeeded.
Verification of component 'chef-provisioning' succeeded.
これで完了です。
Chef Server と違って、reconfiguration は不要です。
ユーザ設定
Chef Workstation上で Cookbook開発をするユーザ設定を実施します。本文書では chefuser01 というユーザを使用することにします。
chefuser01 が ChefDK に同梱されている ruby を使用するよう環境変数を設定します。bash を使用されている場合は、.bash_profile などに設定するのが良いと思います。
[chefuser01@sjchefw01 ~]$ echo 'eval "$(chef shell-init bash)"' >> ~/.bash_profile
[chefuser01@sjchefw01 ~]$ source ~/.bash_profile
[chefuser01@sjchefw01 ~]$ which ruby
/opt/chefdk/embedded/bin/ruby
chef-repo作成
Chef Workstation で使用する リポジトリ を作成します。
リポジトリの名前は自由に決められますが、chef-repo
を使う例が多いようですので、本文書でもそれに倣います。chef-repo は ChefDK に同梱されている chef
コマンドを使用します。ここでは、HomeDir 直下に chef-repo
を作成します。
[chefuser01@sjchefw01 ~]$ pwd
/home/chefuser01
[chefuser01@sjchefw01 ~]$ chef generate app chef-repo
Recipe: code_generator::app
* directory[/home/chefuser01/chef-repo] action create
- create new directory /home/chefuser01/chef-repo
- restore selinux security context
(中略)
* cookbook_file[/home/chefuser01/chef-repo/.gitignore] action create
- create new file /home/chefuser01/chef-repo/.gitignore
- update content in file /home/chefuser01/chef-repo/.gitignore from none to dd37b2
(diff output suppressed by config)
- restore selinux security context
[chefuser01@sjchefw01 ~]$ ls
chef-repo
[chefuser01@sjchefw01 ~]$
chef-repo 設定
Chef Workstation 上の chef-repo と、Chef Server を紐づける設定を実施します。Chef Manage が導入されておらず、WebGUI が使えないので全て CUI で設定します。
具体的には、Chef Server セットアップ時に作成した ユーザと組織の鍵を配置して、設定ファイル(knife.rb
)を作成します。chef-repo 直下に .chef というフォルダを作成し、鍵と knife.rb
を配置します。
Chef Manage が使える環境ではより簡単に設定ができるので、詳細は公式を参照してください。
LEARN CHEF / Install the Chef DK / Manually (w/ Webui)
[chefuser01@sjchefw01 ~]$ mkdir -p ~/chef-repo/.chef/
# ユーザと組織の鍵を配置してください。Permission を 600 に変更します。
[chefuser01@sjchefw01 ~]$ ls -l ~/chef-repo/.chef/
合計 8
-rw-------. 1 chefuser01 myusers 1649 10月 26 01:58 kentarok.pem
-rw-------. 1 chefuser01 myusers 1649 10月 26 01:59 test-validator.pem
Chef Client 12.1.0以降、Chef Workstation上に 組織鍵(上の例では、
test-validator.pem
)の配置が必要なくなりました。
詳しくは knife bootstrapにおけるvalidatorなしでのブートストラップ #getchefを参照してください。
~/chef-repo/.chef/
配下に knife.rb
を作成します。以下の内容で作成するので、コピペしてください。
current_dir = File.dirname(__FILE__)
log_level :info
log_location STDOUT
node_name 'kentarok' # <- ユーザ名
client_key "#{current_dir}/kentarok.pem" # <- ユーザの鍵
validation_client_name 'test-validator' # <- 組織の鍵の拡張子抜いた文字列を設定
validation_key "#{current_dir}/test-validator.pem" # <- 組織の鍵
chef_server_url 'https://sjchefs01.cent7.local/organizations/test' # <- 最後を組織名にする
cache_type 'BasicFile'
cache_options( :path => "#{ENV['HOME']}/.chef/checksums" )
cookbook_path ["#{current_dir}/../cookbooks"]
SSL設定
Chef Server では自己証明書を使用しています。knife.rb
で設定した Chef Server の自己証明書を信頼する設定を行います。設定は knife.rb
が参照できるように chef-repo 配下でコマンドを実行します。
[chefuser01@sjchefw01 ~]$ cd ~/chef-repo/
[chefuser01@sjchefw01 chef-repo]$ knife ssl fetch
WARNING: Certificates from sjchefs01.cent7.local will be fetched and placed in your trusted_cert
directory (/home/chefuser01/chef-repo/.chef/trusted_certs).
Knife has no means to verify these are the correct certificates. You should
verify the authenticity of these certificates after downloading.
Adding certificate for sjchefs01.cent7.local in /home/chefuser01/chef-repo/.chef/trusted_certs/sjchefs01_cent7_local.crt
[chefuser01@sjchefw01 chef-repo]$ knife ssl check
Connecting to host sjchefs01.cent7.local:443
Successfully verified certificates from `sjchefs01.cent7.local'
これで、Chef Server と接続設定が完了しました。Chef Server に実際に接続してみて、情報が返ってくるか確認してみてください。
[chefuser01@sjchefw01 chef-repo]$ knife client list
test-validator
[chefuser01@sjchefw01 chef-repo]$ knife user list
kentarok
4. Chef Node セットアップ for CentOS
Chef の機能を使って、Cookbookを実行し、何らかの設定をしたい(Chefっぽくいうと、何らかの状態に収束させたい)対象のことを Chef Nodeと言います。Chef Nodeとなるためには、Chef Clientを導入します。
が、Chef Client は Chef Workstation から "Bootstrap" という機能の中で、リモートから導入することが可能です。この機能を使って Chef Client を導入する方式がスタンダード且つ便利なので、本文書でもそれに倣い "Bootstrap" 機能を使うことにします。
本セクションでは、適切に Bootstrap されるための前提の設定を Chef Node に対して実施した上で、Chef Workstation から Bootstrap を実行します。
ここでは、Chef Node として、CentOS を対象にします。
Bootstrap で自動導入される Chef Client は、その時点での最新バージョンの Chef Client が導入されます。
オプションで、Chef Client のバージョンを指定することも可能です。
本文書では、執筆時の最新である 12.15.19
が自動導入されています。
また、本セクションでは、以下の公式サイトを参照しています。
Install the Chef DK
補足
Chef Client は rpm や deb、msi といった形式で配布されているので、ダウンロードした上で手動で予め Chef ノードに導入しておくことも可能です。その場合も、Chef Client の初期設定や Chef Serverへの登録処理などを行う必要があるので、"Bootstrap" は必要になります。
Windows を Chef Node として扱いたい場合は、以下の公式を参照してください。
LEARN CHEF / Chef for Microsoft Windows
2016/11/02 追記
Chef Node に Windows Server を使用する場合の手順を記事にしました。
Windows を Chef Node にする手順
ユーザ設定
Chef Node にユーザを作成します。このユーザは Chef Workstation から Chef Node に SSH でログインする際に使用します。また、パスワード認証か公開鍵認証の設定も合わせて実施してください。Chef で使うユーザは公開鍵認証を推奨しますが、ここでは敢えてパスワード認証を選択します。
[root@sjchefn01 ~]# useradd chefuser01
[root@sjchefn01 ~]# passwd chefuser01
ユーザー chefuser01 のパスワードを変更。
新しいパスワード:
新しいパスワードを再入力してください:
passwd: すべての認証トークンが正しく更新できました。
sudo設定
chefuser01 に sudo 経由で root を使う権限を付与します。いろいろ権限を絞るのは面倒なので、ここでは ALL で設定します。NOPASSWD も合わせて設定したほうが便利ですが、ここでは敢えて NOPASSWD は設定していません。
Chef を実行するだけであれば
chef-client
コマンドのみ sudo を許可すれば OK です。が、bootstrap ができなくなるので、別途検証が必要です。
[root@sjchefn01 ~]# echo "" >> /etc/sudoers
[root@sjchefn01 ~]# echo "## Allow chefuser01 to run any commands anywhere" >> /etc/sudoers
[root@sjchefn01 ~]# echo "chefuser01 ALL=(ALL) ALL" >> /etc/sudoers
### NOPASSWD を設定する場合はこちら
[root@sjchefn01 ~]# echo "chefuser01 ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
Bootstrap
それでは、Chef Workstation から Chef Node に対して Bootstrap します。事前に Chef Node を名前解決できるようにしておいてください。
途中で、SSHログインと sudo時にパスワードを聞かれるので入力してください。もちろん、公開鍵認証、NOPASSWD属性をつけている場合は、パスワード入力は不要です。
[chefuser01@sjchefw01 chef-repo]$ knife bootstrap sjchefn01.cent7.local -x chefuser01 --sudo
Doing old-style registration with the validation key at /home/chefuser01/chef-repo/.chef/test-validator.pem...
Delete your validation key in order to use your user credentials instead
Connecting to sjchefn01.cent7.local
chefuser01@sjchefn01.cent7.local's password: ### <- ログインパスワードを入力します
sjchefn01.cent7.local knife sudo password:
Enter your password: ### <- sudo用にパスワードを入力します。
sjchefn01.cent7.local
sjchefn01.cent7.local -----> Installing Chef Omnibus (-v 12)
sjchefn01.cent7.local downloading https://omnitruck-direct.chef.io/chef/install.sh
sjchefn01.cent7.local to file /tmp/install.sh.23998/install.sh
sjchefn01.cent7.local trying wget...
sjchefn01.cent7.local el 7 x86_64
sjchefn01.cent7.local Getting information for chef stable 12 for el...
sjchefn01.cent7.local downloading https://omnitruck-direct.chef.io/stable/chef/metadata?v=12&p=el&pv=7&m=x86_64
sjchefn01.cent7.local to file /tmp/install.sh.24003/metadata.txt
sjchefn01.cent7.local trying wget...
sjchefn01.cent7.local sha1 cd53d4f6431e912d0ddafce3cabd113fec3dda05
sjchefn01.cent7.local sha256 66a514699bddd3f507a3b80b687cd71079a09e2aa01fa8111bee7f06a95c44c7
sjchefn01.cent7.local url https://packages.chef.io/files/stable/chef/12.15.19/el/7/chef-12.15.19-1.el7.x86_64.rpm
sjchefn01.cent7.local version 12.15.19
sjchefn01.cent7.local downloaded metadata file looks valid...
sjchefn01.cent7.local downloading https://packages.chef.io/files/stable/chef/12.15.19/el/7/chef-12.15.19-1.el7.x86_64.rpm ### <- chef-clientをダウンロード中
sjchefn01.cent7.local to file /tmp/install.sh.24003/chef-12.15.19-1.el7.x86_64.rpm
sjchefn01.cent7.local trying wget...
sjchefn01.cent7.local Comparing checksum with sha256sum...
sjchefn01.cent7.local Installing chef 12 ### <- chef-clientを導入
sjchefn01.cent7.local installing with rpm...
sjchefn01.cent7.local 警告: /tmp/install.sh.24003/chef-12.15.19-1.el7.x86_64.rpm: ヘッダー V4 DSA/SHA1 Signature、鍵 ID 83ef826a: NOKEY
sjchefn01.cent7.local 準備しています... ################################# [100%]
sjchefn01.cent7.local 更新中 / インストール中...
sjchefn01.cent7.local 1:chef-12.15.19-1.el7 ################################# [100%]
sjchefn01.cent7.local Thank you for installing Chef!
sjchefn01.cent7.local Starting the first Chef Client run...
sjchefn01.cent7.local Starting Chef Client, version 12.15.19
sjchefn01.cent7.local Creating a new client identity for sjchefn01.cent7.local using the validator key. ### <- Chef Serverへの登録
sjchefn01.cent7.local resolving cookbooks for run list: []
sjchefn01.cent7.local Synchronizing Cookbooks:
sjchefn01.cent7.local Installing Cookbook Gems:
sjchefn01.cent7.local Compiling Cookbooks...
sjchefn01.cent7.local [2016-10-27T02:28:10-05:00] WARN: Node sjchefn01.cent7.local has an empty run list.
sjchefn01.cent7.local Converging 0 resources
sjchefn01.cent7.local
sjchefn01.cent7.local Running handlers:
sjchefn01.cent7.local Running handlers complete
sjchefn01.cent7.local Chef Client finished, 0/0 resources updated in 02 seconds
[chefuser01@sjchefw01 chef-repo]$
これで、sjchefn01.cent7.local が Chef Node として Chef Server に登録されました。
[chefuser01@sjchefw01 chef-repo]$ knife node list
sjchefn01.cent7.local
[root@sjchefn01 chef]# rpm -qa | grep chef
chef-12.15.19-1.el7.x86_64
上記の例では、
knife bootstrap
コマンドの中で、Chef Client の導入モジュールをインターネットからダウンロードして、導入しています。そのため、Chef Node がインターネットに接続できない環境ではエラーになります。
その場合は、"--bootstrap-install-command 'rpm -Uvh /tmp/chef-12.15.19-1.el7.x86_64.rpm"
オプションを追加して、Chef Node にあらかじめ配置しておいた rpmファイルから Chef Client を導入したり、"--bootstrap-url http://10.x.x.x/chef-12.15.19-1.el7.x86_64.rpm"
オプションを追加して、手近なファイルサーバからダウンロードして、Chef Client を導入することも可能です。
5. 稼動確認
Chef Node に 実際に Cookbook を適用して稼動確認をしてみます。
Chef社が公式に提供している chef-client Cookbook を使って、Chef Node に配布された 組織鍵を削除してみます。このファイルは、Chef Node の登録時のみ必要で以降不要となるため、セキュリティを考慮して、Chef Node から削除することが推奨です。
[chefuser01@sjchefn01 ~]$ ls -l /etc/chef/validation.pem
-rw-------. 1 root root 1680 Oct 27 02:28 /etc/chef/validation.pem
knife
コマンドで Cookbook をダウンロードするので、その前提となる git の導入・設定を実施します。
[chefuser01@sjchefw01 chef-repo]$ sudo yum install -y git
(中略)
[chefuser01@sjchefw01 chef-repo]$ git config --global user.email kentarok@jp.ibm.com
[chefuser01@sjchefw01 chef-repo]$ git config --global user.name "kentarok"
[chefuser01@sjchefw01 chef-repo]$ git add *
[chefuser01@sjchefw01 chef-repo]$ git commit -m "1st Commit"
[master (root-commit) 2a3a8ea] 1st Commit
(中略)
[chefuser01@sjchefw01 chef-repo]$
実際に Cookbook をダウンロード・導入します。
knife.rb
で指定された Cookbook Dir に 依存関係のある Cookbook 含めて全て導入されました。
[chefuser01@sjchefw01 chef-repo]$ knife cookbook site install chef-client
(中略)
[chefuser01@sjchefw01 chef-repo]$ ls -l ./cookbooks/
合計 24
drwxr-xr-x. 6 chefuser01 myusers 4096 10月 27 02:58 chef-client
drwxr-xr-x. 4 chefuser01 myusers 4096 10月 26 01:55 chef-repo
drwxr-xr-x. 4 chefuser01 myusers 4096 10月 27 02:58 compat_resource
drwxr-xr-x. 9 chefuser01 myusers 4096 10月 27 02:58 cron
drwxr-xr-x. 7 chefuser01 myusers 4096 10月 27 02:58 logrotate
drwxr-xr-x. 7 chefuser01 myusers 4096 10月 27 02:58 windows
Chef Workstation がインターネットに接続できない場合は、全て手作業で配置する必要があります。
knife
コマンドで導入できる Cookbook は 全て Chef supermarket から入手可能です。
Chef Supermarket
ダウンロードした chef-client Cookbook を Chef Server に Upload します。--include-dependencies
を付与して依存関係のある Cookbook も合わせて Upload します。
[chefuser01@sjchefw01 chef-repo]$ knife cookbook upload chef-client --include-dependencies
Uploading chef-client [7.0.0]
Uploading cron [3.0.0]
Uploading logrotate [2.1.0]
Uploading windows [2.0.2]
Uploading compat_resource [12.16.1]
Uploaded 5 cookbooks.
[chefuser01@sjchefw01 chef-repo]$ knife cookbook list
chef-client 7.0.0
compat_resource 12.16.1
cron 3.0.0
logrotate 2.1.0
windows 2.0.2
Chef Node に対し、chef-client::delete_validation
レシピを実行し、組織鍵を削除します。
[chefuser01@sjchefw01 chef-repo]$ knife ssh name:sjchefn01.cent7.local "sudo chef-client -o 'recipe[chef-client::delete_validation]'" -x chefuser01
chefuser01@sjchefn01.cent7.local's password:
sjchefn01.cent7.local knife sudo password:
Enter your password:
sjchefn01.cent7.local
sjchefn01.cent7.local Starting Chef Client, version 12.15.19
sjchefn01.cent7.local [2016-10-27T03:08:54-05:00] WARN: Run List override has been provided.
sjchefn01.cent7.local [2016-10-27T03:08:54-05:00] WARN: Original Run List: []
sjchefn01.cent7.local [2016-10-27T03:08:54-05:00] WARN: Overridden Run List: [recipe[chef-client::delete_validation]]
sjchefn01.cent7.local resolving cookbooks for run list: ["chef-client::delete_validation"]
sjchefn01.cent7.local Synchronizing Cookbooks:
sjchefn01.cent7.local - cron (3.0.0)
sjchefn01.cent7.local - chef-client (7.0.0)
sjchefn01.cent7.local - logrotate (2.1.0)
sjchefn01.cent7.local - compat_resource (12.16.1)
sjchefn01.cent7.local - windows (2.0.2)
sjchefn01.cent7.local Installing Cookbook Gems:
sjchefn01.cent7.local Compiling Cookbooks...
sjchefn01.cent7.local Converging 1 resources
sjchefn01.cent7.local Recipe: chef-client::delete_validation
sjchefn01.cent7.local * file[/etc/chef/validation.pem] action delete
sjchefn01.cent7.local - delete file /etc/chef/validation.pem
sjchefn01.cent7.local [2016-10-27T03:08:55-05:00] WARN: Skipping final node save because override_runlist was given
sjchefn01.cent7.local
sjchefn01.cent7.local Running handlers:
sjchefn01.cent7.local Running handlers complete
sjchefn01.cent7.local Chef Client finished, 1/1 resources updated in 02 seconds
実際に削除されたか、念のために確認します。ちゃんと削除されていますね。
[chefuser01@sjchefn01 ~]$ ls -l /etc/chef/validation.pem
ls: cannot access /etc/chef/validation.pem: No such file or directory
これで、Chef Server 環境の整備は完了です。