Search code examples
vagrantvirtualboxsalt-project

many configrations of a single machine with a single Vagrant file


I'm using Salt Stack to provision a Virtualbox vm using Vagrant and environment variables passed in from the command line to tell Vagrant which project to configure:

PROJECT='drupal-site' vagrant up

This value is then used to set a Salt minion's ID so that it configures itself correctly. I'm concerned that when a vm is provisioned and configured and then another project is specified from the cli, that the same vm instance will attempt to be configured again for a different project, when what I actually want is two vm instances. I don't want many Vagrant files if a single one will do.

I think this may be possible if I can control Vagrant's :id property but cannot figure out where this is set.

Any insight?


Solution

  • I solved this using Varant's multi-machine setup BUT using only a single machine:

    PROJECT = ENV['PROJECT']
    ...
    config.vm.define PROJECT do |project|
        project.vm.box = "precise64"
        project.vm.host_name = PROJECT + ".localhost"
    ...
    

    Works a treat :D