【问题标题】:Vagrantfile merge/append parametersVagrantfile 合并/附加参数
【发布时间】:2017-06-06 12:42:52
【问题描述】:

我想允许将参数附加到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

【问题讨论】:

  • 使append_params 成为Hash 例如append_params = {x: false, y: false} 然后**append_params 在第 2 行

标签: ruby hashmap


【解决方案1】:

所以最后我找到了适合我的解决方案,因为我有一些 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"})

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-02-17
    • 2020-02-29
    • 1970-01-01
    • 2012-08-21
    • 2011-11-16
    • 2012-05-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多