Vagrant versionning: possible to specify box version on command line ?

67 views
Skip to first unread message

Francois Marot

unread,
Sep 24, 2015, 9:51:21 AM9/24/15
to Vagrant
Hello all,

I have a simple problem: I have many versions of a box, defined in a standard metadata.json file referenced in my Vagrantfile. I will have to regularly switch between versions (to test & compare regressions for example) of boxes. i'd like to avoid hardcoding the box version I want to use in my Vagrantfile (config.vm.box_version parameter).
So is there a way to specify on the 'vagrant up' command-line which version I want to use ? The "--box-version" parameter available for some other command seems not supported :(

Alvaro Miranda Aguilera

unread,
Sep 24, 2015, 7:13:00 PM9/24/15
to vagra...@googlegroups.com
Hello
vagrantfile is ruby

so you can use ruby magic, ie variables

or, what I would do would be:

create this structure

myawesomebox/0.0.0
myawesomebox/0.1.0
myawresomebox/1.0.0

and put a vagrantfile there on each directory

then, you can use

myversion = Pathname.new(Dir.getwd).basename.to_s

and that variable will be the name of the direcrtory

i use that to name the box as the directory, but in your case you can
use it to grab de version.

Alvaro
> --
> This mailing list is governed under the HashiCorp Community Guidelines -
> https://www.hashicorp.com/community-guidelines.html. Behavior in violation
> of those guidelines may result in your removal from this mailing list.
>
> GitHub Issues: https://github.com/mitchellh/vagrant/issues
> IRC: #vagrant on Freenode
> ---
> You received this message because you are subscribed to the Google Groups
> "Vagrant" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to vagrant-up+...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/vagrant-up/02041ceb-bd45-4c8a-8d94-3bafdfc65b03%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

dragon788

unread,
Oct 21, 2015, 3:44:10 PM10/21/15
to Vagrant
You can also read environment variables using Ruby from within the Vagrantfile, so rather than having different folders, you could just "set MYBOXVERSION=0.0.1" then "vagrant box up" and in your Vagrantfile is reads box.version="ENV:$MYBOXVERSION" (this is not real Ruby) and it dynamically loads whatever you exported.
Reply all
Reply to author
Forward
0 new messages