0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【自分用】ChefDKで環境(workstation+node)構築時に利用するコマンド備忘録

Last updated at Posted at 2016-09-06

ChefDKを利用して開発環境構築(Workstation+単一Node)の勉強をしている。
構築時の流れについて、忘れないうちにメモしておく。

仮想マシン作成〜Chefリポジトリ作成&準備

# 初期の場合
# chef gem install knife-solo
# chef gem install berkshelf
# knife configure
# CentOS6.7のboxファイルを取得
$ vagrant box add centos64 vagrant box add centos64 http://developer.nrel.gov/downloads/vagrant-boxes/CentOS-6.4-x86_64-v20131103.box

# centos67で仮想マシンを作成、起動確認
$ vagrant init centos64
$ vagrant up

# ssh設定を追加。ホスト名はmylinuxとする
$ vagrant ssh-config --host mylinux >> ~/.ssh/config  

# mylinuxで、SSH接続ができることを確認
$ ssh mylinux

# 上位ディレクトリに移動し、chefリポジトリを作成
$ cd ../
$ knife solo init chef-repo

# chefリポジトリに移動し、仮想マシンでchefが利用できるようにする
$ cd chef-repo
$ knife solo prepare mylinux

Berksfileへの追記

chef-repo/Berksfile
source "https://api.berkshelf.com"

cookbook "yum"
cookbook "yum-epel"

berksコマンドの実行

$ cd chef-repo
$ berks vendor ./cookbooks

Cookbook作成

# mybookというCookbookを、site-cookbooks配下に作成
$ knife cookbook create mybook -o site-cookbooks/ 

recipeの追記

chef-repo/site-cookbooks/mybook/recipes/default.rb
%w{
mysql-server
httpd
python-devel
git
}.each do |p|
    package p do 
        action :install
    end
end

service "httpd" do 
    action [:start, :enable]
end

nodeへのレシピ情報の追記

chef-repo/nodes/mylinux.json
{
  "run_list": [
    "recipe[yum]",
    "recipe[yum-epel]",
    "recipe[mybook]"
  ]
}
# node(mylinux)への反映
$ knife solo cook mylinux

# 仮想マシンに反映されていることを確認
$ ssh mylinux2

# 仮想マシン上でgitを実行してみる
$ git
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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?