knife-soloでcookbookをリモートホストに実行する際に、毎回 -i オプションでKeyPairファイルを指定するのがめんどくさかったので設定ファイルに記述する方法を調べた。
knife の設定ファイルを作成
knife configre コマンドでknifeの設定ファイルを作成する。
$ knife configure
WARNING: No knife configuration file found
Where should I put the config file? [/home/user_name/.chef/knife.rb]
Please enter the chef server URL: [https://your_hostname:443]
Please enter an existing username or clientname for the API: [user_name]
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):
knife の設定ファイルにKeyPairの設定を記述する
設定の方法は公式サイト(knife ssh — Chef Docs)に書いてあった
公式サイトによるとknife confireを実行した際に作成したknife.rbに対して以下のようにknife[:identity_file]の記述をする。
/home/user_name/.chef/knife.rb
...
knife[:identity_file] = 'IDENTITY_FILE_PATH'
...
knife soloの実行
設定が終わったので実行してみる。
設定前と設定後を一応並べてみる。
- knife[:identity_file]の設定前
$ knife solo cook -i IDENTITY_FILE_PATH remote_hostname
- knife[:identity_file]の設定後
$ knife solo cook remote_hostname
これで毎回 -iでIDENTITY_FILE_PATHを指定しなくて済むようになった。