Vagrantfile合并/追加参数

时间:2017-06-06 12:42:52

标签: ruby hashmap

我想允许将参数附加到config.vm.synced_folder。我希望用户在此配置中附加其他参数。

我到目前为止:

append_params = 'x: false, y: false'
config.vm.synced_folder x['folder'], "/var/www", create: true, type: "nfs", append_params 

如果我删除, append_params则可行。但有了它,它失败了,错误:

There is a syntax error in the following Vagrantfile. The syntax error
message is reproduced below for convenience:
D:/x/Vagrantfile:32: syntax error, unexpected '\n', expecting =>

如何根据请求将其他参数附加到config.vm.synced_folder

1 个答案:

答案 0 :(得分:0)

所以最后我发现解决方案适用于我的情况,因为我有一些config.yml参数可以在Vagrantfile中解析

# config.yml
append_params:
    :someVar: false
    :fsnotify: true

# Vagrantfile
if File.file?("config.yml")
    parameters = YAML.load_file 'config.yml'
else
    parameters = {}
end
...
Vagrant.configure("2") do |config|
    config.ssh.forward_agent = true
    ...
    config.vm.synced_folder parameters['synced_folder'], "/var/www",  parameters['append_params'].merge({create: true, type: "nfs"})