Toby
Toby

Reputation: 55

Git and differing Vagrant files

I have a Vagrant project in a Git repository, but require different Vagrant files for various machines. I'm wondering if there is a way to manage the Vagrant file in Git, rather than having to .gitignore the file and manage them outside of Git.

Upvotes: 0

Views: 124

Answers (2)

Chris Ledet
Chris Ledet

Reputation: 11628

I would have different Vagrant files with their machine name appended to the filenames. Such as: Vagrant.staging, Vagrant.development, Vagrant.production, etc. When you go to deploy, just symlink the relative one to Vagrant.

Upvotes: 0

Adrian Petrescu
Adrian Petrescu

Reputation: 18049

It's usually a really good idea to put your Vagrantfile in source control, since it is often part of your dev and/or test environment.

It sounds like your problem is that each machine needs to make some customizations to the Vagrantfile to make it fit into their environment. This is a common issue – managing configuration files in source control. There's two main approaches:

  • For things that have a small, discrete set of configurations (for instance, per platform), you can put that logic directly into the Vagrantfile. After all, Vagrantfiles are just Ruby code at the end of the day – feel free to put some configuration logic into them.
  • For things that are unique to each individual user, it's best to source those from the environment through (for example) environment variables that the Vagrantfile can read through ENV. This way, you can commit the Vagrantfile and just require end users to configure their environment.

Upvotes: 1

Related Questions