Vagrant
インストール
$ gem install vagrant
Box追加
$ vagrant box add centos-63-minimal https://dl.dropbox.com/u/7225008/Vagrant/CentOS-6.3-x86_64-minimal.box
確認
$ vagrant box list
仮想マシン作成
適当なディレクトリに移動
$ vagrant init centos-63-minimal
Vagrantfileファイルが作成される
起動
$ vagrant up
ログイン
$ vagrant ssh
停止
$ vagrant halt
再起動
$ vagrant reload
参考
サンドボックスモード
インストール
$ vagrant gem install sahara
サンドボックスモードON
$ vagrant sandbox on
ON以降の変更確定
$ vagrant sandbox commit
ONの時の状態に戻す
$ vagrant sandbox rollback
サンドボックスモードOFF
$ vagrant sandbox off
サンドボックスモードか確認
$ vagrant sandbox status
Chef-solo
インストール
$ gem install chef
$ gem install knife-solo
初期化
vagrantのディレクトリで作業
$ knife solo init chef-repo
WARNING: No knife configuration file found
という警告がでるが気にしない
次のようなディレクトリが生成される
chef-repo
├── cookbooks
├── data_bags
├── nodes
├── roles
├── site-cookbooks
└── solo.rb
- cookbooksディレクトリに共通的なやつとかおく
- site-cookbooksディレクトリに固有のやつをおく
レシピ作成
ためしにtestユーザーを追加してみるレシピを作成
$ knife cookbook create adduser -o chef-repo/cookbooks/
cookbooks内に次のようなディレクトリ、ファイルが生成される
chef-repo
├── cookbooks
│ └── adduser
│ ├── CHANGELOG.md
│ ├── README.md
│ ├── attributes
│ ├── definitions
│ ├── files
│ │ └── default
│ ├── libraries
│ ├── metadata.rb
│ ├── providers
│ ├── recipes
│ │ └── default.rb
│ ├── resources
│ └── templates
│ └── default
├── data_bags
├── nodes
├── roles
├── site-cookbooks
└── solo.rb
chef-repo/cookbooks/adduser/recipes/default.rb
を編集
user 'test' do
password 'test'
end
Vagrantの設定を編集
Vagrantfile
を編集
Vagrant::Config.run do |config|
config.vm.box = "centos-63-minimal"
config.vm.provision :chef_solo do |chef|
chef.cookbooks_path = "chef-repo/cookbooks"
chef.add_recipe "adduser"
end
end
Vagrantでchef-soloを実行
Vagrantを再起動してchef-soloを実行
$ vagrant reload
次のような出力がされて実行される
[default] Running provisioner: Vagrant::Provisioners::ChefSolo...
[default] Generating chef JSON and uploading...
[default] Running chef-solo...
[2013-03-16T15:51:05+01:00] INFO: *** Chef 10.12.0 ***
[2013-03-16T15:51:06+01:00] INFO: Setting the run_list to ["recipe[adduser]"] from JSON
[2013-03-16T15:51:06+01:00] INFO: Run List is [recipe[adduser]]
[2013-03-16T15:51:06+01:00] INFO: Run List expands to [adduser]
[2013-03-16T15:51:06+01:00] INFO: Starting Chef Run for localhost
[2013-03-16T15:51:06+01:00] INFO: Running start handlers
[2013-03-16T15:51:06+01:00] INFO: Start handlers complete.
[2013-03-16T15:51:06+01:00] INFO: Processing user[test] action create (adduser::default line 10)
[2013-03-16T15:51:06+01:00] INFO: user[test] created
[2013-03-16T15:51:06+01:00] INFO: Chef Run complete in 0.044201 seconds
[2013-03-16T15:51:06+01:00] INFO: Running report handlers
[2013-03-16T15:51:06+01:00] INFO: Report handlers complete
確認
$ id test
uid=501(test) gid=502(test) 所属グループ=502(test)
Vimを追加してみる
ココに標準のレシピが用意されてるので持ってくる
$ git clone git://github.com/opscode-cookbooks/vim.git chef-repo/cookbooks/vim
Vagrantfile
を編集
Vagrant::Config.run do |config|
config.vm.box = "centos-63-minimal"
config.vm.provision :chef_solo do |chef|
chef.cookbooks_path = "chef-repo/cookbooks"
chef.add_recipe "adduser"
chef.add_recipe "vim" #←追加
end
end
Vagrantを再起動して実行
$ vagrant reload
もしくは次のコマンドで実行
$ vagrant provision