如果我对下面的Vagrantfile尝试vagrant up secondmachine
,则Vagrant将仅创建一个名为“ secondmachine”的Ubuntu VM。但是,Vagrant仍将尝试在其上运行“ firstmachine”脚本。
我如何说服Vagrant只配置它实际启动的和/或在命令行中指定的计算机?遍历多个机器定义是否有正确的方法?
# coding: utf-8
# -*- mode: ruby -*-
# vi: set ft=ruby :
nodes = [
{
:name => "firstmachine",
:autostart => false,
:box => "centos/7",
:provisioners => [
{
:script => "cat /etc/redhat-release",
},
],
},
{
:name => "secondmachine",
:autostart => false,
:box => "ubuntu/trusty64",
:provisioners => [
{
:script => "apt-get update",
},
],
},
]
Vagrant.require_version ">= 2.0.2"
Vagrant.configure("2") do |config|
nodes.each do |node|
# Will ignore any node without a name!
next if node[:name].empty?
config.vm.define node[:name], autostart: node[:autostart] do |machine|
machine.vm.box = node[:box]
node[:provisioners].each do |provisioner|
config.vm.provision
type: "shell",
privileged: privileged,
inline: provisioner[:script]
end
end
end
end
答案 0 :(得分:0)
错误是供应者分配给配置对象,而不是后续的机器实例。简而言之,将config.vm.provision
更改为machine.vm.provision
可以解决问题。