Using Vagrant - nshenry03/chef-repo GitHub Wiki

Vagrant is a tool that makes it easy to work with virtual machines.

You will need to install VirtualBox or some other virtualizer, such as VMware.

You will also need to install Vagrant.

Once Vagrant is installed, I like to install the 'vagrant-butcher' plugin, as it will automatically delete the node and client for you when you run 'vagrant destroy'. If you plan to use Vagrant to provision production servers, you probably do NOT want to install this plugin. To continue with the installation, simply run this command: vagrant plugin install vagrant-butcher.

By default, this repository has the following VirtualBox 'boxes' configured:

  • precise32 - Ubuntu 12.04 LTS (32-bit)
  • precise64 - Ubuntu 12.04 LTS (64-bit)
  • lucid32 - Ubuntu 10.04 LTS (32-bit)
  • lucid64 - Ubuntu 10.04 LTS (64-bit)

You can add more boxes if you'd like.

I also like to configure the following options in the 'Vagrantfile':

  • I like to un-comment config.vm.network :public_network. This allows me to connect to my VM over my local network.
  • I like to un-comment and configure the config.vm.provision :chef_client block of code so that the virtual machines automatically bootstrap with my Chef Server.
  • If you've installed the 'vagrant-butcher' plugin, you may also need to configure the config.butcher.knife_config_file setting.

Booting a virtual machine

Run vagrant up <<VM Name>>; so, for example, you could run vagrant up precise32.

If you configured the 'chef_client' section of the Vagrantfile, you should now be able to run knife node list and see that your VM has been added to the Chef Server.

Connecting to a virtual machine

Run vagrant ssh <<VM Name>>; so, for example, you could run vagrant ssh precise32.

Stopping a virtual machine

  • Suspending the virtual machine by calling vagrant suspend <<VM Name>> will save the current running state of the machine and stop it. When you're ready to begin working again, just run vagrant up <<VM Name>>, and it will be resumed from where you left off. The main benefit of this method is that it is super fast, usually taking only 5 to 10 seconds to stop and start your work. The downside is that the virtual machine still eats up your disk space, and requires even more disk space to store all the state of the virtual machine RAM on disk.

  • Halting the virtual machine by calling vagrant halt <<VM Name>> will gracefully shut down the guest operating system and power down the guest machine. You can use vagrant up <<VM Name>> when you're ready to boot it again. The benefit of this method is that it will cleanly shut down your machine, preserving the contents of disk, and allowing it to be cleanly started again. The downside is that it'll take some extra time to start from a cold boot, and the guest machine still consumes disk space.

  • Destroying the virtual machine by calling the vagrant destroy <<VM Name>> will remove all traces of the guest machine from your system. It'll stop the guest machine, power it down, and remove all of the guest hard disks. Again, when you're ready to work again, just issue a vagrant up <<VM Name>>. The benefit of this is that no cruft is left on your machine. The disk space and RAM consumed by the guest machine is reclaimed and your host machine is left clean. The downside is that vagrant up to get working again will take some extra time since it has to reimport the machine and reprovision it.

If you configured the 'chef_client' section of the Vagrantfile and you installed and configured the 'vagrant-butcher' plugin, you should now be able to run knife node list and see that your VM has been removed from the Chef Server.

⚠️ **GitHub.com Fallback** ⚠️