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.

Vagrant 上に Chef-Soloの環境構築

Last updated at Posted at 2015-08-16

Chef-Soloの環境を作って、クックブックやレシピの開発環境を整備します。
この環境は、Rubyの環境を作った記録で作成した BOX を元にしています。

ベース環境の起動

Chef-Soloを動かすディレクトリを作成して、移動します。

pxedhcp1:Vagrant maho$ mkdir Chef-Solo
pxedhcp1:Vagrant maho$ cd Chef-Solo/
pxedhcp1:Chef-Solo maho$ ls -la
total 0
drwxr-xr-x   2 maho  staff   68  8 16 15:49 .
drwxr-xr-x  21 maho  staff  714  8 16 15:49 ..

BOX名を指定して初期化します。

pxedhcp1:Chef-Solo maho$ vagrant box list
RoRDev_Ubuntu14     (virtualbox, 0)
Ubuntu14.04_minimam (virtualbox, 0)
pxedhcp1:Chef-Solo maho$ vagrant init RoRDev_Ubuntu14

Vagrantfile を編集して、メモリとCPU数を追加、プライベートLANを追加します。

pxedhcp1:Chef-Solo maho$ vi Vagrantfile 

仮想マシンを起動します。

pxedhcp1:Chef-Solo maho$ vagrant up

仮想マシンが起動したらログインして、Chefをインストールしていきます。

pxedhcp1:Chef-Solo maho$ vagrant ssh
Welcome to Ubuntu 14.04 LTS (GNU/Linux 3.13.0-24-generic x86_64)

 * Documentation:  https://help.ubuntu.com/
Last login: Sun Aug 16 05:53:19 2015 from 10.0.2.2
vagrant@vagrant-ubuntu-trusty:~$ 

Chef-Solo のインストール

インストール実行

vagrant@vagrant-ubuntu-trusty:~$ gem install chef
vagrant@vagrant-ubuntu-trusty:~$ gem install knife-solo
vagrant@vagrant-ubuntu-trusty:~$ gem install berkshelf

導入結果確認

vagrant@vagrant-ubuntu-trusty:~$ knife -v
Chef: 12.4.1
vagrant@vagrant-ubuntu-trusty:~$ chef-apply -v
Chef: 12.4.1
vagrant@vagrant-ubuntu-trusty:~$ chef-solo -v
Chef: 12.4.1

リポジトリを作って初期化する

vagrant@vagrant-ubuntu-trusty:~$ mkdir chef-repo
vagrant@vagrant-ubuntu-trusty:~$ cd chef-repo/
vagrant@vagrant-ubuntu-trusty:~/chef-repo$ knife solo init .
WARNING: No knife configuration file found
Creating kitchen...
Creating knife.rb in kitchen...
Creating cupboards...
Setting up Berkshelf...

クックブックを作成する

vagrant@vagrant-ubuntu-trusty:~/chef-repo$ knife cookbook create dstat
** Creating cookbook dstat in /home/vagrant/chef-repo/cookbooks
** Creating README for cookbook: dstat
** Creating CHANGELOG for cookbook: dstat
** Creating metadata for cookbook: dstat

Chef-Client solo クライアントのインストール

rootでログイン可能かたssh鍵が共有されたサーバーに対して、chef-clientをリモートでインストールする

vagrant@vagrant-ubuntu-trusty:~/chef-repo$ knife solo bootstrap 192.168.33.21 -i ~/key/identity 

その他

vagrant + VirtualBoxで動作させる場合に、以下のユーテリティをインストールしておくと、ホストのファイルシステムを共有できる。

root@vagrant-ubuntu-trusty:~# apt-get install virtualbox-guest-utils 
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?