Vagrant for DevOps: Vagrantfile

Vagrantfile is used to deploy the whole infrastructure from scratch on any machine running Vagrant.
Vagrantfile describes environment configuration – stuff like VMs, shares, networking, etc.
Vagrantfile should be stored in VCS, such as Git – we’ll be able to share environment configurations within the team and switch between different environment versions.

Vagrantfile should be stored in the project directory, but if it’s not found there, vagrant will search for it in all dirs from project to / :

Screen Shot 2016-05-25 at 17.02.05
And for security reasons you might want to store Vagrantfiles in a private dir, in this case use environment variable VAGRANT_CWD to specify a path.
If you have a few Vagrantfiles, vagrant will automatically merge them, but it’s not really common practice.

We can generate simple vagrant file with vagrant init command, but we’ll construct our own configuration which would be a bit more complex.
Vagrantfiles are ruby-based, so it’s really easy to have a deal with syntax.

You can use my simple comments in Vagrantfiles to understand basic things, but I recommend you to visit vagrant docks page for more details.

Here’s an example for a single Linux machine:

[pastacode lang=”bash” user=”kagarlickijd” repos=”vagrant” path_id=”linux/Vagrantfile” revision=”” highlight=”” lines=”” provider=”github”/]

[pastacode lang=”bash” user=”kagarlickijd” repos=”vagrant” path_id=”linux/script.sh” revision=”” highlight=”” lines=”” provider=”github”/]

 

And single Windows machine:

[pastacode lang=”bash” user=”kagarlickijd” repos=”vagrant” path_id=”windows/Vagrantfile” revision=”” highlight=”” lines=”” provider=”github”/]

[pastacode lang=”bash” user=”kagarlickijd” repos=”vagrant” path_id=”windows/script.ps1″ revision=”” highlight=”” lines=”” provider=”github”/]

 

A bit more complex example with two Linux VMs:

[pastacode lang=”bash” user=”kagarlickijd” repos=”vagrant” path_id=”linux-farm/Vagrantfile” revision=”” highlight=”” lines=”” provider=”github”/]

[pastacode lang=”bash” user=”kagarlickijd” repos=”vagrant” path_id=”linux-farm/script.sh” revision=”” highlight=”” lines=”” provider=”github”/]

 

Vagrant for DevOps table of contents