Created
September 14, 2011 20:33
-
-
Save erochest/1217700 to your computer and use it in GitHub Desktop.
Basic Sample Vagrantfile, Rakefile combination for working with OpsCode's and SLab's Chef cookbooks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'etc' | |
require 'fileutils' | |
require 'vagrant' | |
task :default => :usage | |
task :usage do | |
puts "You forgot to tell the computer what to do; try one of these commands:" | |
system("rake -T") | |
end | |
# Execute a command in the primary VM and write its output to the screen. | |
def vm_ssh(env, cmd) | |
puts ">>> '#{cmd}'" | |
env.primary_vm.ssh.execute do |ssh| | |
ssh.exec!(cmd) do |channel, stream, data| | |
print data | |
$stdout.flush | |
end | |
end | |
end | |
desc 'Initializes the environment.' | |
task :init => [:clobber, | |
:cookbooks, | |
:up] | |
desc 'Cleans everything out of the environment.' | |
task :clobber do | |
FileUtils.rmtree %w{cookbooks}, :verbose => true | |
env = Vagrant::Environment.new | |
if env.primary_vm.created? | |
puts 'vagrant destroy' | |
env.cli('destroy') | |
end | |
end | |
desc 'Downloads the cookbooks.' | |
task :cookbooks do | |
Dir.mkdir("cookbooks") unless File.directory?("cookbooks") | |
system('git clone --branch=slab https://github.com/erochest/opscode-cookbooks.git cookbooks/opscode') | |
system('git clone https://github.com/scholarslab/cookbooks.git cookbooks/slab') | |
end | |
desc 'This calls Vagrant up.' | |
task :up do | |
env = Vagrant::Environment.new | |
puts 'vagrant up' | |
env.cli('up') | |
end | |
desc 'Do a safe halt on the VM.' | |
task :halt do | |
vm_ssh(Vagrant::Environment.new, 'sudo halt') | |
end | |
desc "cat /tmp/vagrant-chef-1/chef-stacktrace.out." | |
task :chefst do | |
env = Vagrant::Environment.new | |
raise "Must run `vagrant up`" if !env.primary_vm.created? | |
raise "Must be running!" if !env.primary_vm.vm.running? | |
puts "Getting chef stacktrace." | |
vm_ssh(env, "cat /tmp/vagrant-chef-1/chef-stacktrace.out") | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Vagrant::Config.run do |config| | |
config.vm.box = "geoserver2" | |
config.vm.box_url = "http://files.vagrantup.com/lucid32.box" | |
config.vm.network "33.33.33.10" | |
config.vm.provision :chef_solo do |chef| | |
chef.cookbooks_path = [ | |
'cookbooks/opscode', | |
'cookbooks/slab', | |
] | |
# chef.add_recipe 'TODO' | |
chef.add_recipe 'tmux' | |
chef.add_recipe 'vim' | |
chef.json.merge!({ | |
:vim => { | |
:extra_packages => %w{vim-scripts exuberant-ctags ack-grep} | |
}, | |
:domain => [], | |
:openldap => {} | |
}) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment