如何在多机环境中循环 vagrant 配置以在机器之间来回切换? [英] How do I loop vagrant provisioning in multi-machine environments to switch back and forth between machines?

查看:44
本文介绍了如何在多机环境中循环 vagrant 配置以在机器之间来回切换?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个设置 5 节点环境的多机 Vagrantfile.

I have a multi-machine Vagrantfile setting up a 5 node environment.

我一直在环顾四周,想了解您对配置顺序的控制级别,但非常有限:

I've been looking around to see what levels of control you have over the order of provisioning, but it's pretty limited:

https://docs.vagrantup.com/v2/multi-machine/

我想配置 5 个节点,然后返回到第一个节点,并在那里运行其他配置步骤.

I want to provision 5 nodes, then go back to the first node, and run other provisioning steps there.

我的意思是你有一个这样的 Vagrantfile:

What I mean is that you have a Vagrantfile like this:

Vagrant.configure('2') do |config|
   config.vm.provision some stuff

   config.vm.define 'node1' do |node1|
      node1.vm.provision some more stuff
   end

   config.vm.define 'node2' do |node2|
      node2.vm.provision some other stuff
   end

   ... node3 node4 node 5 ...
end

但是在 vagrant 完成启动并配置到 node5 的所有机器之后,我想在 node1 上运行另一个配置器.有谁知道如何做到这一点?也许是一些红宝石黑客?

But after vagrant has finished starting and provisioning the all the machines up to node5, I then want to run another provisioner on node1. Does anyone know how to do this? Maybe some ruby hackery?

推荐答案

一种可能的方法是通过 ssh 在机器之间执行命令.您需要做的唯一额外的事情就是将 vagrant 不安全的私钥复制给每个来宾.

One possible way of doing this is to execute commands between machines from ssh. The only additional thing you need to do is copy the vagrant insecure private key to each of the guests.

然后您可以在集群中的机器之间进行 ssh(总是很方便),也可以执行以下操作:

Then you can ssh between the machines in your cluster (always handy) and also do stuff like this:

Vagrant.configure('2') do |config|
config.vm.provision some stuff

config.vm.define 'node1' do |node1|
  node1.vm.provision some more stuff
end

config.vm.define 'node2' do |node2|
  node2.vm.provision "shell", inline: "/vagrant/bootstrap-webserver.sh"
  node2.vm.provision "shell", inline: "ssh vagrant@node1 sh /vagrant/trigger-build.sh"
end

config.vm.define 'node3' do |node3|
  node3.vm.provision "shell", inline: "/vagrant/create-database.sh"
  node3.vm.provision "shell", inline: "ssh vagrant@node1 sh /vagrant/initialise-database.sh"
end

... node4 node 5 ...
end

您可能还想在来宾的 sshd_config 中设置PasswordAuthentication no",并将-o StrictHostKeyChecking=no"添加到上面的 ssh 命令以使其工作.

You probably also want to set "PasswordAuthentication no" in your sshd_config on the guests and add "-o StrictHostKeyChecking=no" to the ssh command above to get it to work.

这篇关于如何在多机环境中循环 vagrant 配置以在机器之间来回切换?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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