Override Vagrant configuration settings locally (per-dev)

前端 未结 8 1253
说谎
说谎 2021-01-30 02:51

I\'d like the question to be answered in general, but to illustrate it, here\'s a use case:

I\'m using Vagrant for a simple LMAP project. I use standalone Puppet for pro

8条回答
  •  有刺的猬
    2021-01-30 03:37

    To extend on @Willie Wheeler 's answer. My setup is:

    Root
    |-- defaults.yml
    |-- env.yml
    |-- Vagrantfile
    

    Vagrantfile

    # Load local env config
    require 'yaml'
    dir = File.dirname(File.expand_path(__FILE__))
    
    # defaults
    settings = YAML::load_file("#{dir}/defaults.yml")
    
    if File.exist?("#{dir}/env.yml")
        env_settings = YAML::load_file("#{dir}/env.yml")
        settings.merge!(env_settings)
    end
    ...
    # Customize the amount of memory on the VM:
        vb.memory = settings["vb"]["memory"]
    

    defaults.yml

    vb:
      memory: 1024
    

    env.yml

    vb:
      memory: 204
    

    This will merge whatever defaults you have with your per-dev config. Also it is clear to developers what values they can actually change

提交回复
热议问题