You can specify for shell
using inline
in your Vagrantfile
file:
config.vm.provision "shell", inline: %Q(/usr/bin/env FOO=1 BAR=1 bash /path/to/script.sh)
Or load some extra variables from YAML file:
require 'yaml'
dir = File.dirname(File.expand_path(__FILE__))
vconfig = YAML::load_file("#{dir}/config.yml")
config.vm.provision "shell", inline: %Q(/usr/bin/env FOO=#{vconfig['foo']} bash /path/to/script.sh)
Alternatively you may implement some optional arguments from the command line, e.g.:
# Parse optional arguments.
opts = GetoptLong.new(
[ '--foo', GetoptLong::OPTIONAL_ARGUMENT ], # With optional parameter.
[ '--bar', GetoptLong::OPTIONAL_ARGUMENT ], # With optional parameter.files.
)
opts.each do |opt, arg|
case opt
when '--foo'
foo==arg
when '--bar'
bar=arg
end
end
then use: opt['--foo'].to_s
.
See also: How to pass parameter on Vagrant up and have it in the scope of Chef cookbook?