LoginSignup
0
0

More than 5 years have passed since last update.

chef development kitのインストール

Posted at

前提条件

  • OS: 7.6.1810
  • chef development kit: 3.8.14

インストール方法

2019/03/02現在のchefをインストールし、使用する手順を残します。

https://downloads.chef.io/
上記から各種chefをダウンロードできます。
今回は、この中のChef Development Kitをインストールします。

$ sudo rpm -Uvh https://packages.chef.io/files/stable/chefdk/3.8.14/el/7/chefdk-3.8.14-1.el7.x86_64.rpm

$ yum info chefdk
読み込んだプラグイン:fastestmirror
Loading mirror speeds from cached hostfile
 * base: ftp.riken.jp
 * extras: ftp.riken.jp
 * updates: ftp.riken.jp
インストール済みパッケージ
名前                : chefdk
アーキテクチャー    : x86_64
バージョン          : 3.8.14
リリース            : 1.el7
容量                : 491 M
リポジトリー        : installed
要約                : The full stack of chefdk
URL                 : https://www.chef.io
ライセンス          : Apache-2.0
説明                : The full stack of chefdk

$ chef -v
Chef Development Kit Version: 3.8.14
chef-client version: 14.10.9
delivery version: master (9d07501a3b347cc687c902319d23dc32dd5fa621)
berks version: 7.0.7
kitchen version: 1.24.0
inspec version: 3.6.6

設定

  • パスを通す
echo 'export PATH="/opt/chefdk/embedded/bin:$PATH"' >> ~/.bash_profile && source ~/.bash_profile
  • gitのインストール
$ sudo yum install git
  • リポジトリの作成
$ chef generate repo chef-repo
$ cd chef-repo
$ git init
  • 設定変更
$ cat .chef/knife.rb
local_mode true

chef_repo_dir = File.absolute_path( File.dirname(__FILE__) + "/.." )
cookbook_path ["#{chef_repo_dir}/cookbooks", "#{chef_repo_dir}/site-cookbooks"]
node_path     "#{chef_repo_dir}/nodes"
role_path     "#{chef_repo_dir}/roles"
ssl_verify_mode  :verify_peer

テスト実行

  • cookbookの作成
$ mkdir site-bookboos
$ chef generate cookbook site-cookbooks/[cookbook名]
  • recipeの編集
$ site-cookbooks/test-cook/recipes/default.rb

file "/tmp/sample" do
  owner "chef"
  group "chef"
  mode "0600"
  action :create
end
  • roleの作成
$ EDITOR=vim knife role create linux-server
# そのまま保存する

# 確認
$ cat roles/linux-server.json
{
  "name": "linux-server"
}
  • run_listの追加
$ knife role run_list add linux-server test-cook
chef_type:           role
default_attributes:
description:
env_run_lists:
json_class:          Chef::Role
name:                linux-server
override_attributes:
run_list:            recipe[test-cook]
  • environmentの作成
$ EDITOR=vim knife environment create dev
# そのまま保存する

# 確認
$ cat environments/dev.json
{
  "name": "dev"
}
  • nodeの作成
$ EDITOR=vim knife node create localhost
# そのまま保存

# 確認
$ cat nodes/localhost.json
{
  "name": "localhost"
}
$ knife node run_list set localhost role[linux-server]

$ cat nodes/localhost.json
{
  "name": "localhost",
  "normal": {
    "tags": [

    ]
  },
  "run_list": [
    "role[linux-server]"
  ]
}
  • local環境での実行
$ sudo chef-client -z

補足

  • chef には色々なパッケージが用意されている。
    • Chef Workstation
    • Chef Client
    • Chef Server
    • Chef Development Kit
  • Chef Development Kitは、Chef Workstationにもふくまれているので、何が適切かはやりたいことによって異なる。
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0