Passing Vagrant Command Line Parameters

Description

I have been looking for a simple way to pass parameters to Vagrant while specifying their names and without hurting Vagrant's own parameters.

I have seen few different suggested solutions including using ENV\ARGV. I have chosen to use the library GetoptLong

Suggested Solution

The suggested solution is pretty straightforward:

#!ruby
require 'getoptlong'
opts = GetoptLong.new(
        [ '--ssh-key', GetoptLong::OPTIONAL_ARGUMENT ]
)
sshkey = '~/.ssh/id_rsa'
opts.each do |opt, arg|
 case opt
   when '--ssh-key'
    sshkey = arg
 end
end
puts "sshkey #{sshkey}"
Vagrant.configure("2") do |config|
    ...
    config.ssh.private_key_path = sshkey
    ...
end

Usage:

#!bash
$ vagrant up --ssh-key=~/.ssh/github_rsa
$ vagrant provision --ssh-key=~/.ssh/github_rsa