» Vagrantfile

The primary function of the Vagrantfile is to describe the typeof machine required for a project, and how to configure andprovision these machines. Vagrantfiles are called Vagrantfiles becausethe actual literal filename for the file is Vagrantfile (casing does notmatter unless your file system is running in a strict case sensitive mode).

Vagrant is meant to run with one Vagrantfile per project, and the Vagrantfileis supposed to be committed to version control. This allows other developersinvolved in the project to check out the code, run vagrant up, and be ontheir way. Vagrantfiles are portable across every platform Vagrant supports.

The syntax of Vagrantfiles is Ruby, but knowledgeof the Ruby programming language is not necessary to make modifications to theVagrantfile, since it is mostly simple variable assignment. In fact, Ruby is noteven the most popular community Vagrant is used within, which should help showyou that despite not having Ruby knowledge, people are very successful withVagrant.

» Lookup Path

When you run any vagrant command, Vagrant climbs up the directory treelooking for the first Vagrantfile it can find, starting first in thecurrent directory. So if you run vagrant in /home/mitchellh/projects/foo,it will search the following paths in order for a Vagrantfile, until itfinds one:

  1. /home/mitchellh/projects/foo/Vagrantfile
  2. /home/mitchellh/projects/Vagrantfile
  3. /home/mitchellh/Vagrantfile
  4. /home/Vagrantfile
  5. /Vagrantfile

This feature lets you run vagrant from any directory in your project.

You can change the starting directory where Vagrant looks for a Vagrantfileby setting the VAGRANT_CWD environmental variable to some other path.

» Load Order and Merging

An important concept to understand is how Vagrant loads Vagrantfiles. Vagrantactually loads a series of Vagrantfiles, merging the settings as it goes. Thisallows Vagrantfiles of varying level of specificity to override prior settings.Vagrantfiles are loaded in the order shown below. Note that if a Vagrantfileis not found at any step, Vagrant continues with the next step.

  • Vagrantfile packaged with the box that is to be usedfor a given machine.
  • Vagrantfile in your Vagrant home directory (defaults to ~/.vagrant.d).This lets you specify some defaults for your system user.
  • Vagrantfile from the project directory. This is the Vagrantfile that you willbe modifying most of the time.
  • Multi-machine overrides if any.
  • Provider-specific overrides,if any.At each level, settings set will be merged with previous values. What thisexactly means depends on the setting. For most settings, this means thatthe newer setting overrides the older one. However, for things such as definingnetworks, the networks are actually appended to each other. By default, youshould assume that settings will override each other. If the behavior isdifferent, it will be noted in the relevant documentation section.

Within each Vagrantfile, you may specify multiple Vagrant.configure blocks.All configurations will be merged within a single Vagrantfile in the orderthey're defined.

» Available Configuration Options

You can learn more about the available configuration options by clickingthe relevant section in the left navigational area.