Scripting vagrant

114 views
Skip to first unread message

Mark Cheverton

unread,
Jul 18, 2011, 12:16:16 PM7/18/11
to vagra...@googlegroups.com
Hi all,

Trying to understand the details of scripting vagrant within a Rakefile. I'm trying to loop over my chef roles and package out a set of boxes, but I'm not understanding how to access the configuration for provisioning as my Ruby skills are only a few weeks old. Any help appreciated, this is what I have so far:

task :build do
env = Vagrant::Environment.new
env.ui = Vagrant::UI::Shell.new(env, Thor::Base.shell.new)

puts "Building boxes"

puts "Init environment"
env.cli('init','base')

roles.keys.each do |role|
puts "Spinning up vagrant box"
env.cli('up', '--no-provision')

puts "Provisioning role #{role}"
env.config.vm.provisioners.each do |chef|
chef.config.chef_server_url = CHEF_SERVER
chef.config.validation_key_path = "/home/mark/.chef/validation.pem"
chef.config.run_list = "role[#{role}]"
end
env.cli('provision')

puts "Packaging role #{role}"
env.cli('package', '--output', "#{role}.box", '--vagrantfile', 'Vagrantfile')

puts "Destroying VM"
env.cli('destroy')
end
end

This is okay, except its not provisioning anything which I guess is because I'm not setting the per package provision config up properly.

-Mark
--
Mark Cheverton
mark.ch...@ecafe.org
@ennui2342

uk.linkedin.com/in/markcheverton
polis.ecafe.org

Jay Perry

unread,
Apr 6, 2012, 3:44:07 PM4/6/12
to vagra...@googlegroups.com
I have something similar to this setup but my question is more around how you get the output from the provision or up step to STDOUT.  Is that output going somewhere else?

Thanks,
Jay

David Calavera

unread,
Apr 21, 2012, 1:55:13 PM4/21/12
to vagra...@googlegroups.com
I'm quite late to this party, but if you still don't know how to get the output from Vagrant, you need to initialize the environment with something like this:

Vagrant::Environment.new(:ui_class => Vagrant::UI::Basic)

See how it's initialized here:


Since you're not invoking the cli directly the default option when there is no "ui_class" is silent:

Reply all
Reply to author
Forward
0 new messages