简体   繁体   English

如何在vagrant和puppet之间共享主机文件

[英]How to share a hosts file between vagrant and puppet

I am currently converting a large number of EC2 instances to a series of puppet scripts and then using Vagrant to virtualise the rig for local development. 我目前正在将大量的EC2实例转换为一系列series脚本,然后使用Vagrant虚拟化用于本地开发的装备。

I have gotten stuck on managing the network in vagrant and mapping that onto production. 我一直忙于管理流浪汉中的网络并将其映射到生产中。

First I have something like this: 首先,我有这样的事情:

# Main Web Server
config.vm.define :app do |app_config|
    app_config.vm.host_name = "web1"
    app_config.vm.network :hostonly, "10.0.0.2"
    app_config.vm.box = "precise64"

    ...etc
        puppet.manifest_file = "persist/web.pp"
end 

# First DB server
config.vm.define :db1 do |db1_config|
    db1_config.vm.host_name = "db1"
    db1_config.vm.network :hostonly, "10.0.0.3"
    db1_config.vm.box = "precise64"
    ...etc
        puppet.manifest_file = "persist/db.pp"
end

etc.

Then in this case web.pp and db.pp are reasonably simply they just setup python, uwsgi, nginx, mysql etc. 然后在这种情况下,web.pp和db.pp相当简单,它们只需设置python,uwsgi,nginx,mysql等。

So the problem: I need inside for example puppet/modules/hosts/files/hosts have to specify something like: 所以出现了问题:例如,我需要在puppet/modules/hosts/files/hosts指定类似内容:

10.0.0.3    db1.X.com
10.0.0.4    db2.X.com
etc.

In production we use a combination of our sites DNS and ec2 instances DNS records (which I cant put into hosts). 在生产中,我们结合使用了站点DNS和ec2实例DNS记录(我无法将其放入主机)的组合。 Typically our haproxy hosts have a public DNS record and they hold the EC2 names in their config (which makes using a hosts file impossible). 通常,我们的haproxy主机具有公共DNS记录,并且它们在其配置中保存EC2名称(这使得无法使用hosts文件)。

So how can I build a file that both puppet and vagrant can import and use a global mapping such as: 因此,我该如何构建一个文件,木偶和流浪汉都可以导入并使用全局映射,例如:

hosts = {
         web => 10.0.0.2,
         db1 => 10.0.0.3,
         db2 => 10.0.0.4,
}

Which I can access from within puppet templates for example haproxy.cfg but also access from within Vagrant files so i can set vm.network to it as well. 我可以从人偶模板(例如haproxy.cfg访问该文件,也可以从Vagrant文​​件中进行访问,因此我也可以将vm.network设置为它。

Restrictions: 限制条件:

  • Cannot be IP only, must be symbolic name to either IP or DNS 不能仅是IP,必须是IP或DNS的符号名称
  • Cannot use a puppet master (unfortunately not flexible on this one). 不能使用木偶大师(不幸的是,这不是很灵活)。
  • Virtualising the DNS server as well seems messy so id rather not. 虚拟化DNS服务器似乎也很麻烦,因此请使用id而不是。

Also I am really new to ruby, if you provide examples (which would be great) please describe it enough for me to be able to find my way through the ruby docs. 另外,我真的是红宝石的新手,如果您提供示例(那太好了),请对其进行描述,以使我能够通过红宝石文档找到自己的方式。

2 Options: 2个选项:

1) You can have vagrant read a hash that you shown from a file ( placed in it's dir, DB, whatever ) and then generate Vagrantfile using that content. 1)您可以让vagrant从文件(显示在dir,DB等文件中)中读取显示的哈希,然后使用该内容生成Vagrantfile。 Vagrant's config just runs some ruby code ( i think ) if not 流浪者的配置只是运行一些红宝石代码(我认为),如果没有

2) Have a shell script generate Vagrantfile and/or puppet config / static file. 2)让shell脚本生成Vagrantfile和/或puppet config / static文件。

Implementation details are trivial. 实现细节很简单。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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