本地覆盖 Vagrant 配置设置(每个开发者) [英] Override Vagrant configuration settings locally (per-dev)

查看:40
本文介绍了本地覆盖 Vagrant 配置设置(每个开发者)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望对问题进行一般性回答,但为了说明这一点,这里有一个用例:

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

我将 Vagrant 用于一个简单的 LMAP 项目.我使用独立的 Puppet 进行配置.现在,可能有一些开发人员坐在代理后面,他们需要对 VM 进行一些额外的配置.我在 Puppet 方面有一些工作:我可以将代理 IP(如果有)作为事实传递给 Vagrantfile 中的 puppet,如果设置了 Puppet 就会做出相应的反应.

I'm using Vagrant for a simple LMAP project. I use standalone Puppet for provisioning. Now, there might be some developers who sit behind a proxy and they would need some additional configuration to be made to the VM. I have things working on the Puppet side: I can pass the proxy IP (if any) as a fact to puppet in the Vagrantfile and Puppet reacts accordingly if it's set.

我唯一的问题是:开发人员如何在不更改Vagrantfile(受版本控制且必须保持开发环境中立)的情况下为其开发环境指定/覆盖此设置?

The only issue I have is: how can developers specify/override this setting for their development environment without having to change the Vagrantfile (which is under version control and must remain dev-environment-neutral)?

如果人们可以覆盖一个名为例如的文件中的一些 Vagrant 设置,那就太棒了.Vagrantfile.local,我将通过 .gitignore 排除.

If would be awesome if people could override some Vagrant settings in a file called e.g. Vagrantfile.local, which I would exclude via .gitignore.

由于 Vagrantfile 只是 Ruby,我尝试了以下操作:

Since a Vagrantfile is just Ruby, I tried the following:

# Also load per-dev custom vagrant config
custom_vagrantfile = 'Vagrantfile.local'
load custom_vagrantfile if File.exist?(custom_vagrantfile)

文件包含基本上有效,但看起来在包含的文件中,我不再处于同一个 Vagrant 上下文中...

The file inclusion basically works, but it looks like in the included file, I'm not in the same Vagrant context anymore...

Vagrant::Config.run do |config|
  config.vm.provision :puppet do |puppet|
    puppet.facter = { "proxy" => "proxy.host:80" }
  end
end

... 还重置"了我在主 Vagrantfile 中创建的所有其他 puppet 配置值,这让我觉得我在这里走错了方向.我应该注意,我对 Ruby 完全是个菜鸟 ;)

... also "resets" all other puppet config values I made in the main Vagrantfile, which makes me think I'm heading in the wrong direction here. I should note that I'm a total noob at Ruby ;)

任何人都可以给我一个提示,甚至是一个可行的解决方案,说明如何在这里完成每个开发者的定制?

Can anyone give me a hint or even a working solution for how per-dev customization could be done here in general?

推荐答案

我建议使用环境变量来动态更改 Vagrantfile 的行为,而无需编辑文件本身.

I would suggest using environment variables to dynamically change the behavior of the Vagrantfile without editing the file itself.

举一个真实世界的例子,这里是你如何在默认情况下使用 Ubuntu 基础框,但有一个环境变量定义一个替代的 Linux 发行版:

To give a real world example, here's how you could use an Ubuntu base box by default but have an environment variable define an alternative Linux distribution:

if ENV['OPERATINGSYSTEM']
  if ENV['OPERATINGSYSTEM'].downcase == 'redhat'
    os_name = 'centos'
    config.vm.box     = 'centos'
    config.vm.box_url = 'https://dl.dropbox.com/u/7225008/Vagrant/CentOS-6.3-x86_64-minimal.box'
  else
    raise(Exception, "undefined operatingsystem: #{ENV['OPERATINGSYSTEM']}")
  end
else
  os_name = 'precise64'
  config.vm.box     = 'precise64'
  config.vm.box_url = 'http://files.vagrantup.com/precise64.box'
end

这个例子来自https://github.com/puppetlabs/puppetlabs-openstack_dev_env

这篇关于本地覆盖 Vagrant 配置设置(每个开发者)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆