Vagrant 通过具有不同配置的PuPHPet的多个流浪VM

Vagrant 通过具有不同配置的PuPHPet的多个流浪VM,vagrant,puppet,vagrantfile,puphpet,Vagrant,Puppet,Vagrantfile,Puphpet,我觉得我错过了一些基本的东西。如何使用PuPHPet在一个vagrant文件中定义两台机器,都是Ubuntu 14.04,但一台安装了mysql,另一台安装了elasticsearch?我知道如何定义多台机器,但每台机器的配置似乎都是相同的???这不是通过PuPHPet GUI本机支持的,但是。。。您可以轻松地实现它 注意:我不会通过PuPHPet的github跟踪器提供以下支持。请不要邮寄这张票。然而,我使用的东西类似于一些自由职业者的客户,它工作得很好 PuPHPet支持多个配置文件,每个配

我觉得我错过了一些基本的东西。如何使用PuPHPet在一个vagrant文件中定义两台机器,都是Ubuntu 14.04,但一台安装了mysql,另一台安装了elasticsearch?我知道如何定义多台机器,但每台机器的配置似乎都是相同的???

这不是通过PuPHPet GUI本机支持的,但是。。。您可以轻松地实现它

注意:我不会通过PuPHPet的github跟踪器提供以下支持。请不要邮寄这张票。然而,我使用的东西类似于一些自由职业者的客户,它工作得很好

PuPHPet支持多个配置文件,每个配置文件都扩展并覆盖上一个配置文件

看看
puphpet/puppet/hiera.yaml

---
:backends: yaml
:yaml:
    :datadir: '/'
:hierarchy:
    - vagrant/puphpet/config-custom
    - vagrant/puphpet/config-%{::provisioner_type}
    - vagrant/puphpet/config
:merge_behavior: deeper
:logger: console
mongodb:
    install: '0'
    settings:
        bind_ip: 127.0.0.1
        port: '27017'
    globals:
        version: 2.6.0
    databases: {  }
Hiera向后加载配置文件,因此它将进入
config.yaml
->
config-%{::provisioner_type}.yaml
->
config custom.yaml

您可以在下面插入新行
config custom
-vagrant/puphpet/config-%{::server\u type}

这会将此文件中的任何自定义设置注入到Puppet环境中。但是,您仍然需要让Vagrant意识到这一点,因为Vagrant从
Vagrantfile
读取命令。您可能还需要为每种不同的服务器类型做一些自定义工作。请注意,在此上下文中,
server\u type
可以表示代理、应用、数据库、jenkins等

在存在
Vagrantfile
PuPHPet
目录的PuPHPet根目录中,创建以服务器类型命名的新目录

例如,创建一个新的
db
目录,删除您的
Vagrantfile
并在此新目录中创建一个新目录,然后在
puphpet
目录中创建一个
config db.yaml

$ tree -L 2
.
├── db
│   └── Vagrantfile
└── puphpet
    ├── config-custom.yaml
    ├── config-custom.yaml.dist
    ├── config-db.yaml
    ├── config.yaml
    ├── files
    ├── puppet
    ├── ruby
    ├── shell
    └── vagrant
您的
db/Vagrantfile
内容可以如下所示:

# -*- mode: ruby -*-

dir = File.dirname(File.expand_path(__FILE__))
dir = "#{dir}/.."

server_type = 'proxy'

VAGRANT_DOTFILE_PATH = "#{dir}/.vagrant";
currpath = ENV['VAGRANT_DOTFILE_PATH'];
if(currpath.nil?)
    currpath = '.vagrant';
end
if(currpath != VAGRANT_DOTFILE_PATH)
    ENV['VAGRANT_DOTFILE_PATH'] = VAGRANT_DOTFILE_PATH
    args = ARGV.join(' ');
    system "vagrant #{args}"

    if Dir.exists?('Directory Name')
        FileUtils.rm_r(currpath)
    end

    abort "Finished"
end

require 'yaml'
require "#{dir}/puphpet/ruby/deep_merge.rb"
require "#{dir}/puphpet/ruby/to_bool.rb"
require "#{dir}/puphpet/ruby/puppet.rb"

configValues = YAML.load_file("#{dir}/puphpet/config.yaml")

provider = ENV['VAGRANT_DEFAULT_PROVIDER'] ? ENV['VAGRANT_DEFAULT_PROVIDER'] : 'local'
if File.file?("#{dir}/puphpet/config-#{provider}.yaml")
  custom = YAML.load_file("#{dir}/puphpet/config-#{provider}.yaml")
  configValues.deep_merge!(custom)
end

if File.file?("#{dir}/puphpet/config-#{server_type}.yaml")
  custom = YAML.load_file("#{dir}/puphpet/config-#{server_type}.yaml")
  configValues.deep_merge!(custom)
end

if File.file?("#{dir}/puphpet/config-custom.yaml")
  custom = YAML.load_file("#{dir}/puphpet/config-custom.yaml")
  configValues.deep_merge!(custom)
end

data = configValues['vagrantfile']

Vagrant.require_version '>= 1.8.1'

Vagrant.configure('2') do |config|
  eval File.read("#{dir}/puphpet/vagrant/Vagrantfile-#{data['target']}")
end
我们现在已经告诉Vagrant关于新配置文件的信息,地址是
{dir}/puphpet/config-{server_type}.yaml
->
{dir}/puphpet/config db.yaml
->

根据需要为任意多个服务器类型创建尽可能多的这些类型

如果您想让Puppet知道
服务器类型
值,可以将其作为一个因素传递进来。使用以下内容更新
vagrant/vagrant文件-*
文件:

puppet.facter = {
    'server_name'      => "#{machine['id']}",
    'server_type'      => "#{server_type}",
    'fqdn'             => "#{machine_id.vm.hostname}",
    'ssh_username'     => "#{ssh_username}",
    'provisioner_type' => 'local',
}
它将在您的Puppet清单中作为
$::server\u type
提供

这到底是怎么回事

嗯,在
config.yaml
(即主配置文件)中,您可以设置服务器场的基本设置。每台服务器可能需要像
git
这样的软件包,或者防火墙会打开特定的端口。您可以在那里添加这些值

将特定于服务器的应用程序设置为不在
config.yaml
中安装:

---
:backends: yaml
:yaml:
    :datadir: '/'
:hierarchy:
    - vagrant/puphpet/config-custom
    - vagrant/puphpet/config-%{::provisioner_type}
    - vagrant/puphpet/config
:merge_behavior: deeper
:logger: console
mongodb:
    install: '0'
    settings:
        bind_ip: 127.0.0.1
        port: '27017'
    globals:
        version: 2.6.0
    databases: {  }
config db.yaml
中,您可以根据需要设置特定于数据库的值:

mongodb:
    install: '1'
    settings:
        ensure: true
        package_name: mongodb-org-server
        bind_ip: "%{::ipaddress_tun0}"
        port: '27017'
        config: /etc/mongod.conf
        replset: rsmain
    globals:
        bind_ip: "%{::ipaddress_tun0}"
        version: 3.2.6
        service_name: mongodb
    databases:
         your_db:
             name: db_name
             user: db_user
             password: 'awesome_password'
现在,数据库服务器将接收这些更改并根据需要应用。您的应用程序服务器(或jenkins/proxy/etc)仍会认为
mongodb
不需要从
config.yaml
安装。您可以通过这种方式创建相当复杂的农场,只需使用几个simpel YAML文件即可

最后要注意的是,由于这是一个多服务器环境,所以Vagrant需要知道在运行大多数命令时使用哪台服务器。您可以通过使用机器ID来实现这一点,您需要在每个
config-#{server\u type}.yaml
文件中设置机器ID。每个文件可以为其类型定义多台计算机。然后只需将机器ID附加到vagrant命令:

vagrant up db1
vagrant destroy-f db1


我希望这能回答你所有的问题,或者至少能帮助你实现你的目标

配置可能是相同的,但是如果您查看每台机器的
puphpet/config.yaml
,它将是相同的different@FrédéricHenri谢谢,但我指的是从单个(PuPHPet生成的)文件中创建的多台机器。PuPHPet允许您在一个文件中创建多台计算机,但除了最基本的信息(主机名和IP)外,它们似乎是彼此的克隆。这与:puphpet multi-machine基于vagrant multi-machine(请参阅:通过此最新更新,您可以创建相同的机器,您可以将其部署到您想要的任何提供程序)中描述的用例完全不同但是,您可以很容易地复制config.yaml并在每台机器上创建一个,这样您就可以提供不同的软件。您如何将一个文件指向多个config.yaml?