install Vagrant and Chef in Ubuntu
$ sudo apt-get install vagrant chef$ chef-client -v
Chef: 10.12.0
install Knife
$ knife configure
$ edit ~/.chef/knife.rb
cookbook_path [ './site-cookbooks' ]
use Knife to create a Cookbook
$ knife cookbook create beer** Creating cookbook beer
** Creating README for cookbook: beer
** Creating CHANGELOG for cookbook: beer
** Creating metadata for cookbook: beer
When the "beer" cookbook runs, it creates a file in /tmp
$ edit site-cookbooks/beer/recipes/default.rb
File.open('/tmp/beer.txt', 'w') {|f| f.write('tasty\n') }
Tell Vagrant to use Chef, and to run "beer" recipe
$ edit Vagrantfile
config.vm.provision :chef_solo do |chef|
chef.cookbooks_path = "site-cookbooks"
chef.add_recipe "beer"
end
Boot the VM, thus running chef-client and our beer recipe
$ vagrant up
Verify it worked
$ vagrant ssh -c 'cat /tmp/beer.txt'
tasty
No comments:
Post a Comment