简体   繁体   中英

Vagrantfile merge/append parameters

I want to allow appending of parameters to config.vm.synced_folder . I want users to append additional parameters to this config.

I have so far:

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

If I remove , append_params it works. But with it, it fails with error:

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 =>

How can I append additional parameters on request to config.vm.synced_folder ?

So finally I found the solution that works in my case as I have some config.yml with parameters that get parsed inside 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"})

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM