## devops.rbrequire "sysadmin/1.0"require "sysadmin/2.0/virtualization"require "sysadmin/2.0/automation"
Vagrant usa VirtualBox come provider multipiattaforma:
$ sudo apt-get install virtualbox
NOTA: virtualbox e kvm non vanno molto daccordo ;-)
Su Linux è possibile far uso di un provider non ufficiale basato su LXC:
$ sudo apt-get install lxc...$ vagrant plugin install vagrant-lxc...
Vagrant.configure("2") do |config|config.vm.define :raring64 do |raring_config|raring_config.vm.box = 'raring64'raring_config.vm.hostname = "lab-raring64"raring_config.vm.provider 'virtualbox' do |vm|vm.box_url = "http://BOXURL.box"vm.customize ['modifyvm', :id, '--memory', '512']# vm.gui = trueendendend
Vagrant.configure("2") do |config|config.vm.define :raring64 do |raring_config|raring_config.vm.box = 'raring64'raring_config.vm.hostname = "lab-raring64"raring_config.vm.provider 'lxc' do |vm|vm.box_url = "http://BOXURL.box"vm.customize 'cgroup.memory.limit_in_bytes', '512M'endendend
$ vagrant box add raring64 VBOX_BOX_URL... # add base raring64 box (virtualbox)$ vagrant box add raring64 LXC_BOX_URL... # add base raring64 box (lxc)
$ vagrant up raring64 [--provider=lxc]... # create vm, run provision$ vagrant ssh raring64... # connect to the defined vm
Vagrant.configure("2") do |config|config.vm.define :raring64 do |raring_config|...endconfig.vm.provision :shell, :path => "./prepare.sh"end
$ vagrant provision raring64... # rerun defined provisioners$ vagrant reload raring64... # restart vm and rerun defined provisioners
which chef-solo || (sudo true && \curl -L https://www.opscode.com/chef/install.sh | \sudo bash)
which chef-solo || (sudo true && \curl -L https://www.opscode.com/chef/install.sh | \sudo bash)
which chef-solo || (sudo true && \curl -L https://www.opscode.com/chef/install.sh | \sudo bash)
name "my_project"maintainer "Luca Greco"maintainer_email "luca.greco@alcacoop.it"license "GPLv3"description "my project cookbook"long_description "..."version "0.0.1"
http://docs.opscode.com/chef/resources.html
package, script, template, file, cookbook_file, template_file, remote_file, directory, scm, git, subversion, service, mount, cron, ...
# Cookbook Name:: my_project# Recipe:: www_dependenciespackage 'ruby'package 'rubygems'gem_package 'bundler'
# Cookbook Name:: my_project# Recipe:: www_deploybash 'my_project_bundle_install' douser 'root'pwd '/srv/app_name'code <<-EOCbundle installEOCaction :nothingend...
...git "/srv/app_name" dorepository node[:app_name][:git_repository]reference node[:app_name][:git_revision]action :syncnotifies :run, "bash[my_project_bundle_install]"end...
...cookbook_file "/etc/myapp-monitor/notifications.yml" dosource "notifications.yml"end...
...template_file "/srv/app_name/config/database.yml" dosource "database.yml.erb"variables(:db_address => node[:app_name][:db_address])end...
production:adapter: mysqldatabase: my_projecthost: <%= @db_address %>username: userpassword: ****pool: 5timeout: 5000
default[:app_name][:db_address] = '127.0.0.1'default[:app_name][:git_repository] = '...'default[:app_name][:git_revision] = '...'
...config.vm.provision :chef_solo do |chef|chef.provisioning_path = '/etc/vagrant-chef'# chef.log_level = :infochef.run_list = %w[my_project::wwwmy_project::dbmy_project::email]...
...chef.json = {app_name: {git_repository: '...',git_revision: '...'}}...

name "my_project"maintainer "Luca Greco"maintainer_email "luca.greco@alcacoop.it"license "GPLv3"description "my project cookbook"long_description "..."version "0.0.1"depends 'apache2', "= 1.6.2"
site :opscode### dependencies auto-recognized from metadata and### downloaded by opscode community cookbooks site.metadata### or from a path / git repository:# cookbook "apache2",# :path => '../my_temporary_apache2_fork'# cookbook "apache2",# :git => "GIT REPO URL",# :branch => GIT_BRANCH_NAME"
$ vagrant plugin install vagrant-berkshelf...$ vagrant up --provider=lxc[sudo] password for rpl:Bringing machine 'raring64' up with 'lxc' provider...[raring64] Importing base box 'raring64'...[Berkshelf] Updating Vagrant's berkshelf: '~/.berkshelf...[Berkshelf] Using minitest-handler (0.2.0)[Berkshelf] Using my_project (0.0.1) at path: '/my_project'[Berkshelf] Using chef_handler (1.1.4)[Berkshelf] Using openssh (1.1.4)...
...[raring64] Setting up mount entries for shared folders...[raring64] -- /vagrant[raring64] -- /etc/vagrant-chef/chef-solo-1/cookbooks[raring64] Starting container...[raring64] Waiting for container to start. This should not......